2
votes

My database version 5.6.34

I am using case statement like

SELECT 
    customerName, state, country
FROM
    customers
ORDER BY (CASE
    WHEN state IS NULL THEN country
    ELSE state
END);

table name is customers

I am writting this query in mysql database under SQL, i also attached my table you can see there,

The issue is

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'state IS NULL THEN country     ELSE state END) LIMIT 0, 25' at line 6

it will be really grateful for me if anybody help me please

1
Don't use hard spaces, such as MS Word generates. - Rick James

1 Answers

2
votes

Just remove that ()

SELECT 
    customerName, state, country
FROM
    customers
ORDER BY CASE
    WHEN state IS NULL THEN country
    ELSE state
END