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

(06-14-2017, 02:56 PM)ivantcholakov Wrote: @skunkbad

Code:
-- Filling a dropdown menu about citizenship
(SELECT 'XX' AS country_code, '-- Not specified' AS country_name)
UNION
-- The most probable option(s) is moved on top for user convenience
(SELECT country_code, country_name FROM countries
WHERE country_code IN ('US')
ORDER BY country_name ASC)
UNION
(SELECT country_code, country_name FROM countries
WHERE country_code NOT IN ('US')
ORDER BY country_name ASC)

1) I know you know that you could just put that in $this->db->query().

2) I'd probably just pull them in in a single query and then process them through PHP.

3) That query could be simplified with an "ORDER BY `country_name` = 'United States', `country_name` ASC", and add the empty option with PHP.

4) I suppose if you want MySQL to do all the work, you're right.
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 kilishan - 06-14-2017, 08:26 PM



Theme © iAndrew 2016 - Forum software by © MyBB