List:General Discussion« Previous MessageNext Message »
From:Simon Wilkinson Date:January 12 2011 2:09pm
Subject:Re: help with query
View as plain text  
Thank you, that did the trick.

Simon

On 11 January 2011 12:09, Steve Meyers <steve-mysql-list@stripped> 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
>

Thread
help with querySimon Wilkinson11 Jan
  • Re: help with querySteve Meyers11 Jan
    • Re: help with querySimon Wilkinson12 Jan