title: Codeigniter 4 Complex UNION queries
body: <p>I am new to Codeigniter 4 and trying to write SELECT UNION SQL Statements. According to the user guide in codeigniter 4, there is a second parameter in select() method that allows to write custom SQL Statements by setting it to false. Unfortunately it is not working. Can someone help please? Is there any alternate solution?</p>
  <pre><code>$query = &quot;SELECT acnt_id, acnt_opbal as sum_amount 
                          FROM accounts 
                              WHERE acnt_id = '&quot; . $acnt_id . &quot;' 
                      UNION 
                      SELECT txn_acnt_id_dr as acnt_id, SUM(txn_amount_dr) as sum_amount 
                          FROM transactions 
                              WHERE txn_acnt_id_dr = '&quot; . $acnt_id . &quot;' 
                                  AND txn_date &lt; '&quot; . $fdate . &quot;'
                              GROUP BY txn_acnt_id_dr 
                      UNION 
                      SELECT txn_acnt_id_cr as acnt_id, -SUM(txn_amount_cr) as sum_amount 
                          FROM transactions 
                              WHERE txn_acnt_id_cr = '&quot; . $acnt_id . &quot;' 
                                  AND txn_date &lt; '&quot; . $fdate . &quot;'
                              GROUP BY txn_acnt_id_cr&quot;;
  $result = $this-&gt;builder()-&gt;select($query, false)-&gt;get()-&gt;getResult();
  </code></pre>