LEFT OUTER JOIN question - Mailing list pgsql-sql

From seiliki
Subject LEFT OUTER JOIN question
Date
Msg-id 1209918484.14262.seiliki@so-net.net.tw
Whole thread Raw
Responses Re: LEFT OUTER JOIN question
Re: LEFT OUTER JOIN question
List pgsql-sql
Hi!

I expect the SELECT to return two rows. Would some kind
soul explain for me why it gives only one row?

TIA

CN
=============
CREATE TABLE x(c1 text,c2 int2);
INSERT INTO x VALUES('a',10);
INSERT INTO x VALUES('b',NULL);

CREATE TABLE y(c1 int2,c2 int2,c3 text);
INSERT INTO y VALUES(10,9,'yyy');

CREATE TABLE z(c1 text,c2 text);
INSERT INTO z VALUES('a','zzz');
INSERT INTO z VALUES('b','zzzz');

SELECT x.c1,y.c3,z.c2
FROM x JOIN z USING (c1) LEFT OUTER JOIN y ON (x.c2=y.c1)
WHERE y.c2=9;
c1 | c3  | c2
----+-----+-----a  | yyy | zzz

=========================
Comment: The following version of SELECT does return two
rows as expected, however:

SELECT x.c1,y.c3,z.c2
FROM x JOIN z USING (c1) LEFT OUTER JOIN y ON (x.c2=y.c1);
c1 | c3  |  c2
----+-----+------a  | yyy | zzzb  |     | zzzz


pgsql-sql by date:

Previous
From: Volkan YAZICI
Date:
Subject: Re: update with multiple fields as aggregates
Next
From: Craig Ringer
Date:
Subject: Re: LEFT OUTER JOIN question