[英]returning null or empty string in “IN CLAUSE” mysql php
我有這個問題:
SELECT * from tbl WHERE id = 1 AND option IN (1,2,3)
表:
+-------+---------+-------+
| id | option | votes |
+-------+---------+-------+
| 1 | 1 | 100 |
| 1 | 2 | 150 |
+-------+---------+-------+
由於選項no.3在表中尚不存在,我希望它返回null /空字符串,所以我可以在我的php代碼中將'votes'設置為0。
目前它只給出了我所期望的選項1和2的行。
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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.