Re: [GENERAL] Different LEFT JOIN results with and without USING - Mailing list pgsql-general

From Tom Lane
Subject Re: [GENERAL] Different LEFT JOIN results with and without USING
Date
Msg-id 5893.1487688376@sss.pgh.pa.us
Whole thread Raw
In response to [GENERAL] Different LEFT JOIN results with and without USING  (Alexander Farber <alexander.farber@gmail.com>)
List pgsql-general
Alexander Farber <alexander.farber@gmail.com> writes:
> why do these queries please return different results?

>     FROM    words_scores s
>         LEFT JOIN words_games g ON s.gid = g.gid
>         AND   s.uid = 1

In this one, "s.uid = 1" is part of the LEFT JOIN condition, so it never
eliminates s rows.  Rows not satisfying the condition will be
null-extended instead.

>     FROM    words_scores s
>         LEFT JOIN words_games g USING(gid)
>         WHERE s.uid = 1

In this one, it's part of the top-level WHERE, so it does eliminate s
rows.

            regards, tom lane


pgsql-general by date:

Previous
From: Melvin Davidson
Date:
Subject: Re: [GENERAL] Move rows from one database to other
Next
From: Moreno Andreo
Date:
Subject: Re: [GENERAL] Move rows from one database to other