Home >Backend Development >PHP Tutorial >How to Execute UNION Queries with CodeIgniter's Active Record Pattern?
Performing UNION Queries with CodeIgniter's Active Record Pattern
CodeIgniter's Active Record pattern offers a convenient way to interact with your database using an object-oriented syntax. However, it does not natively support the UNION operation. This limitation doesn't prevent you from executing UNION queries, but you will need to resort to the raw SQL query format.
To perform a UNION query using CodeIgniter's Active Record pattern, follow these steps:
SELECT column_name(s) FROM table_name1 UNION SELECT column_name(s) FROM table_name2
$this->db->query('SELECT column_name(s) FROM table_name1 UNION SELECT column_name(s) FROM table_name2');
The query() method returns a result object that can be used to retrieve the data from the query.
The above is the detailed content of How to Execute UNION Queries with CodeIgniter's Active Record Pattern?. For more information, please follow other related articles on the PHP Chinese website!