Re: Different LEFT JOIN results with and without USING

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Alexander Farber <alexander(dot)farber(at)gmail(dot)com>
Cc: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: Different LEFT JOIN results with and without USING
Date: 2017-02-21 14:46:16
Message-ID: 5893.1487688376@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Alexander Farber <alexander(dot)farber(at)gmail(dot)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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Moreno Andreo 2017-02-21 15:30:47 Re: Move rows from one database to other
Previous Message Melvin Davidson 2017-02-21 14:38:30 Re: Move rows from one database to other