I am using CASE statement in mysql query and I have to check if a column exists or not in the same query.
Is it possible to do so? If yes please help.
My query as example -
SELECT CASE column1 WHEN 'status' THEN 'status' WHEN 'value' THEN (select CASE id WHEN id IS NOT NULL THEN 'status1' ELSE 'status2' END AS ScheduleStatus from table1 where condition ) END AS Status FROM table2 LEFT JOIN table1 ON ... WHERE condition ..;
In above query, when execute it I am getting the result "status2" (else part) even if he condition satisfy. If the "id" row does not exists at that time the result should be "status1". Please correct me.