views:

895

answers:

3

I'm using a stored procedure in MySQL, with a CASE statement.

In the ELSE clause of the CASE ( equivalent to default: ) I want to select and return an empty result set, thus avoiding to throw an SQL error by not handling the ELSE case, and instead return an empty result set as if a regular query would have returned no rows.

So far I've managed to do so using something like:
Select NULL From users Where False

But I have to name an existing table, like 'users' in this example. It works, but I would prefer a more elegant way that doesn't break if eventually the table name used is renamed or dropped.

I've tried Select NULL Where False but it doesn't work.

Using Select NULL does not return an empty set, but one row with a column named NULL and with a NULL value.

+8  A: 

There's a dummy-table in MySQL called 'dual', which you should be able to use.

select
    1
from
    dual
where
    false

This will always give you an empty result.

Björn
Thanks! plus 15 characters
Petruza
+1  A: 

How about this?

SELECT 'MyName' as EmptyColumn
WHERE 'Me' = 'Funny'
Raj More
I've tried something like this, but I guess using Where without From is not legal at least in MySQL, dunno ANSI SQL.
Petruza
A: 

How about

 SELECT * FROM (SELECT 1) AS TBL WHERE 2=3

Checked in myphp, and it also works in sqlite and probably in any other db engine.

Maksee