The Little Guy Posted October 13, 2011 Share Posted October 13, 2011 I need to get a list of all the members in a table that have not purchased these products: 14,42,29,86,43,9,44,12,45 I thought that this would work but doesn't: select m.member_id from members m join purchases p on(m.member_id = p.member_id) where and level_id = 3 and is_active and p.product_id not in(14,42,29,86,43,9,44,12,45) group by member_id; I can not figure this out, thanks for any help! Link to comment https://forums.phpfreaks.com/topic/249053-have-not-purchased-any-of-these-products/ Share on other sites More sharing options...
The Little Guy Posted October 13, 2011 Author Share Posted October 13, 2011 Looks like I got it with this code: select m.member_id from members m join purchases p on(m.member_id = p.member_id) where level_id = 3 and is_active and m.reg_date >= unix_timestamp('2010-01-01') and ( m.member_id not in(select member_id from purchases where product_id = 14) and m.member_id not in(select member_id from purchases where product_id = 42) and m.member_id not in(select member_id from purchases where product_id = 29) and m.member_id not in(select member_id from purchases where product_id = 86) and m.member_id not in(select member_id from purchases where product_id = 43) and m.member_id not in(select member_id from purchases where product_id = 9) and m.member_id not in(select member_id from purchases where product_id = 44) and m.member_id not in(select member_id from purchases where product_id = 12) and m.member_id not in(select member_id from purchases where product_id = 45) ) group by member_id; Link to comment https://forums.phpfreaks.com/topic/249053-have-not-purchased-any-of-these-products/#findComment-1279047 Share on other sites More sharing options...
gizmola Posted October 13, 2011 Share Posted October 13, 2011 I need to get a list of all the members in a table that have not purchased these products: 14,42,29,86,43,9,44,12,45 I thought that this would work but doesn't: select m.member_id from members m join purchases p on(m.member_id = p.member_id) where and level_id = 3 and is_active and p.product_id not in(14,42,29,86,43,9,44,12,45) group by member_id; I can not figure this out, thanks for any help! select m.member_id from members m join purchases p on(m.member_id = p.member_id AND p.product_id not IN (14,42,29,86,43,9,44,12,45)) where level_id = 3 and is_active group by member_id; Link to comment https://forums.phpfreaks.com/topic/249053-have-not-purchased-any-of-these-products/#findComment-1279090 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.