MYSQL query to return rows that are NOT in a set
Posted
by iglurat
on Stack Overflow
See other posts from Stack Overflow
or by iglurat
Published on 2010-03-31T02:52:20Z
Indexed on
2010/03/31
3:03 UTC
Read the original article
Hit count: 365
mysql
Hi,
I have two tables:
Contact (id,name) Link (id, contact_id, source_id)
I have the following query which works that returns the contacts with the source_id of 8 in the Link table.
SELECT name FROM `Contact` LEFT JOIN Link ON Link.contact_id = Contact.id WHERE Link.source_id=8;
However I am a little stumped on how to return a list of all the contacts which are NOT associated with source_id of 8. A simple != will not work as contacts without any links are not returned.
Thanks.
© Stack Overflow or respective owner