How do I write a conditional statement (IF) with MySQL? 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;
What you want is a CASE expression which is standard-SQL method of implementing a conditional and supported by every major database,

SELECT CASE WHEN 1 = 1 THEN 1 ELSE 12 END;


Or you can use the totally silly and proprietary IF statement

SELECT IF( 1=1, 1, 12 );