digitalgod Posted June 7, 2008 Share Posted June 7, 2008 hey guys, ok not sure how I'll explain this but here goes I have 2 tables members +-------+-------------+---------------+ | id | username | email | +-------+-------------+---------------+ | 1 | user1 | [email protected] | | 2 | user2 | [email protected] | | 3 | user3 | [email protected] | +-------+-------------+---------------+ friends +-------+-------------+---------------+ | id | owner | member | +-------+-------------+---------------+ | 510 | 18489 | 3 | +-------+-------------+---------------+ I want to select all the members that match an array of emails like so SELECT id,username FROM members WHERE email IN ( '$list' ) but at the same time I don't want it to return results for entries that are in the friend table. So say that my id is 18489 and that I'm looking for [email protected], [email protected] and [email protected] it will only return id 1 and 2 because id 3 is in the table friends and I ("owner" 18489) am the owner.. what do I have to add in my initial query in order to achieve that don't know if that makes any sense... any help would be greatly appreciated! Link to comment https://forums.phpfreaks.com/topic/109070-solved-query-help/ Share on other sites More sharing options...
digitalgod Posted June 7, 2008 Author Share Posted June 7, 2008 SELECT id,username FROM members WHERE email IN ( '$list' ) AND id NOT IN ( SELECT members FROM friends WHERE owner =18489 ) thanks sasa! Link to comment https://forums.phpfreaks.com/topic/109070-solved-query-help/#findComment-559685 Share on other sites More sharing options...
fenway Posted June 7, 2008 Share Posted June 7, 2008 A LEFT JOIN is also an option here... Link to comment https://forums.phpfreaks.com/topic/109070-solved-query-help/#findComment-560025 Share on other sites More sharing options...
digitalgod Posted June 7, 2008 Author Share Posted June 7, 2008 hey fenway, I tried using a left join but I kept getting double entries ( if not more), most likely my query wasn't good. which option would save more resources? Link to comment https://forums.phpfreaks.com/topic/109070-solved-query-help/#findComment-560064 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.