title: Using union in codeigniter query builder, and filter in a virtual mysql column
body: <p>In my project I am using datatables plugin with serverside processing. It works fine untill i do a search or order(sort) operation because it needs active record to do that.</p>
  
  <p>My scenario is, i have an account table, revenue table and payment table, and I want to view all the data of revenue and payment table, thats why I need a union. my query is like below---</p>
  
  <pre><code>SELECT 'Income' as source, fld_type, fld_amount, ta.fld_account as account,  fld_date, tbl_revenue.fld_description as fld_traninfo, tbl_revenue.fld_created as created
          FROM tbl_revenue JOIN tbl_accounts as ta on tbl_revenue.fld_account_id = ta.fld_id
  UNION
  SELECT 'Expense' as source, fld_type, fld_amount, tae.fld_account, fld_date, tbl_payment.fld_description as fld_traninfo, tbl_payment.fld_created as created
          FROM tbl_payment JOIN tbl_accounts as tae on tbl_payment.fld_account_id = tae.fld_id
  </code></pre>
  
  <p>Is there any way to use query builder in this query?</p>
  
  <p>And second question, you can see I created a virtual column named 'source', i want to filter this column using where clause with append this query like below</p>
  
  <pre><code>WHERE source like "%a%" limit(10,0)
  </code></pre>
  
  <p>But this returns that I don't have any column name 'source', how can I filter this column?</p>
  
  <p>Any help is appreciated.</p>