I have two tables like below:
cat
+-------------------------------+
| id | 1 | 2 | 3 | 4 | 5 |
+-------------------------------+
| name | Hi | Ho | Hu | Ha | He |
+-------------------------------+
selected cat
+----------------+
| id | 2 | 5 |
+----------------+
| name | Ho | He |
+----------------+
Expected Output:
1 - > No
2 - > Yes
3 - > No
4 - > No
5 - > Yes
select id,
case when id in (select distinct id from selected_cat) then 'Yes'
else 'No' end
as somecol
from cat;
You can use a case
statement to check for the existence of id in the other table.