0

I want to define a MySQL stored procedure, which returns data in the result set. Sometimes, I want to return nothing (ie, zero rows).

How can I do this? SELECT; is invalid, and SELECT NULL; returns a record with a NULL value. How to select an empty set?

galinette
  • 8,896
  • 2
  • 36
  • 87

2 Answers2

2

This does the trick:

mysql> select null from dual where 1=0;
Empty set (0.00 sec)
Marc B
  • 356,200
  • 43
  • 426
  • 500
0

The selected answer will work, but I prefer this approach:

SELECT NULL LIMIT 0

It should also work on for other variants of SQL besides just MySQL.

sam-6174
  • 3,104
  • 1
  • 33
  • 34