-2

I want to write something like

if(?) x elseif(?) y else z

and also I want to use CASE WHEN FOR THIS.

2
  • 1
    And what trouble is that giving you? Commented Jun 9, 2017 at 22:24
  • Mysql manual describes the syntax for case. Commented Jun 9, 2017 at 22:35

1 Answer 1

1

MySql has IF(cond, true, false). You can nest them.

So you can do IF(a, x, IF(b, y, z)) for if(a) x elseif(b) y else z

You can also write

      CASE WHEN a THEN x
           WHEN b THEN y
                  ELSE z END

to do the same thing. Pretty straightforward. Some other makes of DBMS server use IIF() instead of IF().

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.