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

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: WHERE ... IN condition and multiple columns in subquery
Дата
Msg-id 14473.1477663608@sss.pgh.pa.us
обсуждение исходный текст
Ответ на WHERE ... IN condition and multiple columns in subquery  (Alexander Farber <alexander.farber@gmail.com>)
Список pgsql-general
Alexander Farber <alexander.farber@gmail.com> 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


В списке pgsql-general по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: deadlock error - version 8.4 on CentOS 6
Следующее
От: Steve Clark
Дата:
Сообщение: Re: deadlock error - version 8.4 on CentOS 6