openlang

What is the MySQL SELECT syntax for a conditional expression?

I'm working in MySQL and would like something resembling a ternary expression in SQL, for example:

SELECT MEMBER_ID, ((MEMBER_ID = 2) ? 1 : 0) AS IS_CHOSEN
FROM MEMBER

The output would look roughly like:

MEMBER_ID | IS_CHOSEN
2         | 1
3         | 0
4         | 0
and so on.

What's the way to express that?

The conversation continues 2

Follow the reasoning

Other sides of the same question

  1. Missing field through a derived table in SQL

    I'm executing the following SQL statement: It produces the following error: #1054 - Unknown column 'shipping.post_id' in 'on…

    Replies 2Latest activity sql
  2. Testing D arrays for a matching entry

    with associative arrays this is possible how is this done with ordinary arrays? I'd like a validation expression, for example

    Replies 2Latest activity d
  3. Removing an optional column safely with PostgreSQL 9+

    I want to remove a column belonging to a table. What's the way to determine whether that column is present? I read the manual…

    Replies 2Latest activity sql