mysql> SELECT
-> IF(status='EndSP',reportId,'') as 'reportId_EndSP'
-> FROM T_Name LIMIT 10;
+--------------+
| reportId_EndSP |
+--------------+
| |
| |
| 270241 |
| |
| 270242 |
| |
| |
| 270244 |
| |
| |
+--------------+
10 rows in set (0.00 sec)
But i need to return only the row where status = 'EndSP'
I don't need the else clause to be executed.
I can simply achieve that by writing
SELECT reportId FROM T_Name where status='EndSP';
but i need to do it using if or case.
EDIT/UPDATE
My actual query looks like
SELECT
-> IF(status='EndSP',reportId,'') as 'reportId_EndSP',
-> IF(status='EndSP',createdTS,'') as 'createdTS_EndSP',
-> IF(status='BeginSP',reportId,'') as 'reportId_BeginSP',
-> IF(status='BeginSP',createdTS,'') as 'createdTS_BeginSP'
-> FROM T_Name HAVING reportId_EndSP!='' AND reportId_BeginSP!='' LIMIT 10;