What is wrong in below simple query? I tried to google it but not found
IF 1 = 1 THEN
SELECT 1;
ELSE
SELECT 12;
END IF;
caseMySQL
What is wrong in below simple query? I tried to google it but not found
IF 1 = 1 THEN
SELECT 1;
ELSE
SELECT 12;
END IF;
Best Answer
I believe that syntax is actually valid; you can find similar statements in the MySQL documentation.
However, it's considered a control flow statement, and those are only allowed in stored programs in MySQL. You don't state that this is inside a stored program, so I'll assume it's not. If it is, please edit your question to provide more detail.
If you're trying to do this outside a stored program, see Evan Carroll's answer.