twikkistep Posted August 3, 2006 Share Posted August 3, 2006 I'm trying to get a grip on JOIN statements -- if I have a table with contacts, and another table with communication entries connected to the first table with contactid, how can I look up this: "select 5 random contacts that have more than 3 communication entries"? Thanks for helping a newbie out. Quote Link to comment Share on other sites More sharing options...
fenway Posted August 3, 2006 Share Posted August 3, 2006 Give this a try (UNTESTED):[code]SELECT ct.*, cm.contactid, COUNT(*) AS entries FROM communications AS cm LEFT JOIN contacts AS ct ON( ct.id = cm.contactid ) GROUP BY cm.contactid HAVING entries > 3 ORDER BY RAND() LIMIT 5 [/code] Quote Link to comment 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.