Thank you, that did the trick. Simon
On 11 January 2011 12:09, Steve Meyers <steve-mysql-l...@spamwiz.com> wrote: > On 1/11/11 9:31 AM, Simon Wilkinson wrote: > >> select users.id from users where users.id in (select newletters.user_id >> from >> newletters left join articles on newletters.id = articles.newsletter_id >> where articles.newsletter_id is null); >> > > I think this would do what you require: > > SELECT > u.id AS user_id, > COUNT(DISTINCT n.id) AS num_newsletters, > COUNT(DISTINCT a.id) AS num_articles > > FROM > users u > JOIN newsletters n ON n.user_id=u.id > LEFT JOIN articles a ON a.newsletter_id=n.id > > GROUP BY > u.id > > HAVING > num_newsletters > 0 > AND num_articles = 0 >