MySQL IFNULL question

Dan picture Dan · Jan 27, 2010 · Viewed 16.2k times · Source

I have a query which contains a subquery which is something like this

IFNULL((SELECT id FROM mytable WHERE id = 1), 'No')

It works OK, but I would like to return the string 'Yes' on success rather than the actual id of the row.

Is there any way to override the value it returns?

Thanks.

Answer

Jan Hančič picture Jan Hančič · Jan 27, 2010
IFNULL((SELECT 'Yes' FROM mytable WHERE id = 1), 'No')