I have this query :
SELECT * from tbl WHERE id = 1 AND option IN (1,2,3)
table :
+-------+---------+-------+
| id | option | votes |
+-------+---------+-------+
| 1 | 1 | 100 |
| 1 | 2 | 150 |
+-------+---------+-------+
As option no.3 doesnt exist yet in the table, i want it to return null / empty string, so i can set 'votes' to 0 in my php code.
Currently it only gives me rows of option 1 & 2 as expected.
SELECT * from tbl t1
RIGHT JOIN
(SELECT 1 AS opt UNION ALL
SELECT 2 AS opt UNION ALL
SELECT 3 AS opt UNION ALL
) t2
ON t1.option = t2.opt
WHERE t1.id = 1