I have a mysql query:
SELECT zip AS z FROM zip WHERE zip = 90210;
| z |
| 90210 |
Empty set (0.01 sec)
| z |
SELECT EXISTS(SELECT zip AS z FROM zip WHERE zip = 90210);
To guarantee that a query returns one row, you can use aggregation. Here is one method:
SELECT COALESCE(MAX(zip), 'false') AS z FROM zip WHERE zip = '90210';
This assumes that
zip is a string, so the types are compatible. If not, you might want to convert it to a string because you are clearly expected a string back.
As for your method, you would need to use a
case statement, which in turn, would require another subquery to get the zip. Hence, I prefer the above method.