Welcome Guest, Not a member yet? Register   Sign In
Add union() to DB Query Builder
#6

UNION is just a tool and it is programmer's responsibility to decide where and why to use it.

db->union(): I can imagine something else (CI3-like syntax):

Code:
$result = $this->db
    ->union_start()
        ->select("'XX' AS country_code, '-- Not specified --' AS country_name")
    ->union_end()
    ->union_start()
        ->select("country_code, country_name")
        ->from('countries')
        ->where_in('country_code', array('US'))
        ->order_by('country_name', 'asc')
    ->union_end()
    ->union_start()
        ->select("country_code, country_name")
        ->from('countries')
        ->where_not_in('country_code', array('US'))
        ->order_by('country_name', 'asc')
    ->union_end()
    // For other cases: A place for clauses that affect the whole result: ORDER BY, LIMIT, etc.
    ->get()
    ->result_array();

The only problem is how hard the implementation of UNION would be.
Reply


Messages In This Thread
Add union() to DB Query Builder - by krystian2160 - 06-14-2017, 08:26 AM
RE: Add union() to DB Query Builder - by skunkbad - 06-14-2017, 11:04 AM
RE: Add union() to DB Query Builder - by zurtri - 06-14-2017, 04:09 PM
RE: Add union() to DB Query Builder - by skunkbad - 06-14-2017, 05:58 PM
RE: Add union() to DB Query Builder - by ivantcholakov - 06-14-2017, 05:30 PM
RE: Add union() to DB Query Builder - by kilishan - 06-14-2017, 08:26 PM



Theme © iAndrew 2016 - Forum software by © MyBB