Yes or No following a sql request without using IF or CASE

advertisements

Is there a way to make a query and return 'yes' or 'no' as an answer without the use of Flow Control operators?

The only solution I thought is:

select 'yes' as answer
from blabla
where blabla

but this of course works only if the query found some results.


I like your blabla but don't understand your goal.

What is wrong with IF() statement or CASE WHEN ELSE END?

If you like your blabla code you can continue the same logic:

select 'yes' as answer
from blabla
where blabla.column=1
UNION
select 'no' as answer
from blabla
where blabla.column<>1

and here is another tricky solution:

http://sqlfiddle.com/#!9/76065/24

SELECT @answer
FROM (
  SELECT @answer:='yes'
  FROM blabla
  WHERE blabla.id=5
) y
RIGHT JOIN (SELECT @answer:='no') n
ON 1;