Re: Join three tables and specify criteria... I know this should be easy!

From: Ken Benson <Ken(at)infowerks(dot)com>
To: "pgsql-novice(at)postgresql(dot)org" <pgsql-novice(at)postgresql(dot)org>
Subject: Re: Join three tables and specify criteria... I know this should be easy!
Date: 2014-08-29 18:42:07
Message-ID: 20ffac5ef5d44358b819b0248ac19d33@BY2PR02MB028.namprd02.prod.outlook.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Which is MUCH cleaner than my next proposed solution:

SELECT DISTINCT u.user_id,u.user_name
FROM user u
JOIN user_language ul
ON u.user_id = ul.ul_user_id
JOIN language l
ON ul.ul_iso_code = l.iso_code
WHERE ul.ul_iso_code = 'EN'
AND ul.ul_iso_code = 'DE';

Writes,

Ken Benson

> -----Original Message-----
> From: pgsql-novice-owner(at)postgresql(dot)org [mailto:pgsql-novice-owner(at)postgresql(dot)org] On
> Behalf Of Kevin Grittner
> Sent: Friday, August 29, 2014 11:13 AM
> To: Paul Linehan; Chuck Roberts
> Cc: pgsql-novice(at)postgresql(dot)org
> Subject: Re: [NOVICE] Join three tables and specify criteria... I know this should be easy!
>
> Paul Linehan <linehanp(at)tcd(dot)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
>
>
> --
> Sent via pgsql-novice mailing list (pgsql-novice(at)postgresql(dot)org) To make changes to your
> subscription:
> http://www.postgresql.org/mailpref/pgsql-novice

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Jude DaShiell 2014-08-29 19:18:35 Re: showing weekdays of dates
Previous Message Jude DaShiell 2014-08-29 18:14:18 logical fields with defaults