Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UNION query with codeigniter's active record pattern

How to do UNION query with PHP CodeIgniter framework's active record query format?

like image 869
strike_noir Avatar asked Jan 11 '10 08:01

strike_noir


People also ask

Do UNION queries run in parallel?

The UNION should run in parallel, at least since SQL Server 2005. It doesn't make a difference if the tables are located on different drives or the same drive. In the modern world, disk can be virtual, or have multiple read heads. The distinction between one drive and more than one drive is less and less relevant.

How do you UNION multiple queries?

To combine result set of two or more queries using the UNION operator, these are the basic rules that you must follow: First, the number and the orders of columns that appear in all SELECT statements must be the same. Second, the data types of columns must be the same or compatible.

How do you count a UNION query?

Here is the query to count on the union query. mysql> select count(*) as UnionCount from -> ( -> select distinct UserId from union_Table1 -> union -> select distinct UserId from union_Table2 -> )tbl1; The following is the output displaying the count.


1 Answers

CodeIgniter's ActiveRecord doesn't support UNION, so you would just write your query and use the ActiveRecord's query method.

$this->db->query('SELECT column_name(s) FROM table_name1 UNION SELECT column_name(s) FROM table_name2'); 
like image 172
Zack Avatar answered Oct 01 '22 11:10

Zack