Search Postgresql Archives

Re: WHERE ... IN condition and multiple columns in subquery

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 28 October 2016 at 13:03, Alexander Farber
<alexander.farber@xxxxxxxxx> wrote:
> Hello,
>
> is it please possible to rewrite the SQL query
>
>         SELECT DISTINCT ON (uid)
>         uid,
>         female,
>         given,
>                 photo,
>                 place
>         FROM words_social
>         WHERE uid IN (SELECT player1 FROM games)
>                 OR uid IN (SELECT player2 FROM games)
>         ORDER BY uid, stamp DESC
>
> where first column player1 is fetched in a subquery and then column player2
> is fetched from the same table?
>
> I've searched around and it seems that a JOIN should be used here, but can
> not figure out exactly how.
>
> Thank you
> Alex

You mean like this?:

         SELECT DISTINCT ON (uid)
                 uid,
                 female,
                 given,
                 photo,
                 place
         FROM words_social
         JOIN games ON uid IN (player1, player2)
         ORDER BY uid, stamp DESC


-- 
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux