nexe Posted August 1, 2007 Share Posted August 1, 2007 hi I have the following tables Subscribers table ID | Email 1 | email1@email.com 2 | email2@email.com 3 | email3@email.com 4 | email4@email.com and a table that hold information about what subscribers are attached to what lists so a subscriber can be assigned to more then one list. ID | subscriber_id | listid 1 | 3 | 1 2 | 2 | 1 3 | 1 | 1 Now i have the query select * from subscribers left join sub_lists on subscribers.id = sub_lists.subscribers_id where listid = 1 this all works fine but I'm having trouble working out a query to return all subscribers that are not assigned to a list. somthing like select * from subscribers left join sub_lists on subscribers.id = sub_lists.subscribers_id where <subscriber.id not in sub_lists> ??? Quote Link to comment https://forums.phpfreaks.com/topic/62775-solved-return-data-thats-not-found-in-another-table/ Share on other sites More sharing options...
btherl Posted August 1, 2007 Share Posted August 1, 2007 select * from subscribers left join sub_lists on subscribers.id = sub_lists.subscribers_id where sub_lists.subscriber_id is null There you go You can use any column from the right table when checking for null from a left join .. I use the joining column for convenience. The reason is that the left join fills in nulls for all columns of the right table when there is no match. Quote Link to comment https://forums.phpfreaks.com/topic/62775-solved-return-data-thats-not-found-in-another-table/#findComment-312533 Share on other sites More sharing options...
nexe Posted August 1, 2007 Author Share Posted August 1, 2007 omg you champion I knew it was worth asking. many many thanks Quote Link to comment https://forums.phpfreaks.com/topic/62775-solved-return-data-thats-not-found-in-another-table/#findComment-312541 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.