I’m working with a Query constructor and thus am somewhat constrained in that I can merely alter the construction of the query, not pull the results together from multiple queries.
Thus, I am looking for a way to return two results from a single table, with a column of group_name
- where group_name = ”
- where group_name != ”
I’d like to return exactly two results, one which meets each criteria. Is there some way to do this via WHERE clauses, subqueries, CASE, or control flow statements?
Note, cannot use UNIONs, due to this old, constrained, query builder, I can however do Group By, Where, and a few other things.
Ultimately, I believe it should be the same result set as if you combined these two queries:
SELECT * from business where group_name = ” LIMIT 1;
SELECT * from business where group_name != ” LIMIT 1;
Try
This returns the first record in the table for which
group_nameis ”, and the first for which it!=''.And if you wanted to select say one record each for
group_namebeing ”, ‘asdf’, or anything else, you could do:This assigns a value of 1 to anything with
group_namebeing'', a value of 2 to anything withgroup_namebeing'asdf', and a value of 3 to everything else.Since there is a
GROUP BYit picks one record (the first occuring) for each.(for your information:
CASEdocumentation.)