我有两张如下表:
cat
+-------------------------------+
| id | 1 | 2 | 3 | 4 | 5 |
+-------------------------------+
| name | Hi | Ho | Hu | Ha | He |
+-------------------------------+
选择了猫
+----------------+
| id | 2 | 5 |
+----------------+
| name | Ho | He |
+----------------+
预期输出:
1 - > No
2 - > Yes
3 - > No
4 - > No
5 - > Yes
答案 0 :(得分:0)
select id,
case when id in (select distinct id from selected_cat) then 'Yes'
else 'No' end
as somecol
from cat;
您可以使用case
语句检查另一个表中是否存在id。