MySQL IF Condition

In my request, I have an IF statement:

IF(friend.block, 'yes', 'no') 

where the value of friend.block is 0 or 1 .. but in any case put it “yes” .. any idea?

+3
source share
3 answers

Link: MySQL Reference

Syntax:

IF (friend.block = 1) THEN
    'Yes'
ELSE
    'No'
END IF

You can use the case statement:

CASE friend.block WHEN 1 THEN "Yes" WHEN 0 THEN "NO" END

+3
source

friend.blockmust have a type INTEGERfor this, or you need to put a companion there:

IF(friend.block != 0, 'yes', 'no')
+7
source
CASE friend.block WHEN 1 THEN 'yes' WHEN 0 THEN 'no' END
0

Source: https://habr.com/ru/post/1719877/


All Articles