Re: Join three tables and specify criteria... I know this should be easy! - Mailing list pgsql-novice

From Kevin Grittner
Subject Re: Join three tables and specify criteria... I know this should be easy!
Date
Msg-id 1409335981.48899.YahooMailNeo@web122306.mail.ne1.yahoo.com
Whole thread Raw
In response to Join three tables and specify criteria... I know this should be easy!  (Paul Linehan <linehanp@tcd.ie>)
Responses Re: Join three tables and specify criteria... I know this should be easy!  (Ken Benson <Ken@infowerks.com>)
Re: Join three tables and specify criteria... I know this should be easy!  (David G Johnston <david.g.johnston@gmail.com>)
List pgsql-novice
Paul Linehan <linehanp@tcd.ie> wrote:
> I really want Sandor's id - that's all that really counts.

>
> Give me the ids of all who speak 'EN' and 'DE' (or
> possibly 'EN', 'DE', 'NL' and 'FR') for example.

WITH required_languages(iso_code) AS (VALUES ('EN'),('DE'))
SELECT u.user_id, u.user_name
  FROM (
          SELECT ul.ul_user_id, count(*) cnt
            FROM required_languages r
            JOIN user_language ul on (ul.ul_iso_code = r.iso_code)
            GROUP BY ul.ul_user_id
            HAVING count(*) >= (SELECT count(*) FROM required_languages r2)
       ) x
  JOIN "user" u ON (u.user_id = x.ul_user_id);

--
Kevin Grittner
EDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


pgsql-novice by date:

Previous
From: Paul Linehan
Date:
Subject: Re: Join three tables and specify criteria... I know this should be easy!
Next
From: Jude DaShiell
Date:
Subject: logical fields with defaults