Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using SELECT for simple BOOLEAN evaluation

I want to test some evaluations without working on any table. For example, you can write

SELECT 1+1
>2

I want to achieve something like this:

SELECT 2 > 1
>FALSE

I know that most engines don't have the concept of a boolean data type, but I don't know how their internal work (even if I guess everything <> 0 is true, like in C). Anyway, the format of the response really doesn't matter, whether it's true/false or 0/1

like image 408
Raffaele Avatar asked Dec 02 '11 14:12

Raffaele


2 Answers

SELECT CASE WHEN 2 > 1 THEN 'True' ELSE 'False' END
like image 173
MatBailie Avatar answered Sep 18 '22 15:09

MatBailie


SELECT
  CASE
    WHEN 2 > 1 THEN 1
    ELSE 0
  END
like image 36
Asken Avatar answered Sep 17 '22 15:09

Asken