Search Postgresql Archives

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

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

 



Alexander Farber <alexander.farber@xxxxxxxxx> writes:
> 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

You could do

    WHERE uid IN (SELECT player1 FROM games UNION SELECT player2 FROM games)

(or possibly UNION ALL would be a trifle faster).  This still reads the
"games" CTE twice; but since you're evaluating that CTE elsewhere in the
query, I think the additional follower node isn't worth trying to get
rid of.

			regards, tom lane


-- 
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