I am trying to get id's from a specific table except from those ids from another table and it does not work:
SELECT id FROM table1
EXCEPT
SELECT id FROM table2
You can try this:
SELECT id FROM table1
where id not in (SELECT id FROM table2)
MYSQL does not support EXCEPT
I don't think mysql supports EXCEPT. Instead try this way :
SELECT t1.id
FROM table1 t1
WHERE NOT EXISTS
( SELECT 0
FROM table2 t2
WHERE t2.id = t1.id )
Use Not IN
SELECT `id` FROM `table1`
WHERE `id` NOT IN (SELECT `id` FROM `table2`);
For more information you can take a look at MySQL NOT IN() function.
You can also use Left Join
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With