Reputation: 323
How to get the IDs which doesn't have any record in the table? Like for example,
select id,name,mail from users where id in(2,3,4,5,6)
The query returns output for the record 2,3,4 but not 5 and 6 as there is no record exists in the table.
Now i want to know what are the ids that doesn't have record in the table. Is there any way to get this output in mysql?
Upvotes: 0
Views: 84
Reputation: 36087
Try:
SELECT id
FROM (
SELECT 2 as id
union
SELECT 3
union
SELECT 4
union
SELECT 5
union
SELECT 6
) q
WHERE q.id NOT IN ( SELECT id FROM users )
Upvotes: 2