From: | Scara Maccai <m_lists(at)yahoo(dot)it> |
---|---|
To: | pgsql-general <pgsql-general(at)postgresql(dot)org> |
Subject: | left outer join without rows from "left" table |
Date: | 2009-02-16 08:15:47 |
Message-ID: | 591966.52151.qm@web24611.mail.ird.yahoo.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Hi all,
I want to get data from these tables:
TABID
integer id,
name varchar
example values:
1 'id1'
2 'id2'
[...]
TABA
integer id,
timestamp t,
integer a
example values:
1 '2009-02-13 00:00:00' 10
1 '2009-02-13 02:00:00' 19
TABB
integer id,
timestamp t,
integer b
example values:
1 '2009-02-13 00:00:00' 90
1 '2009-02-13 01:00:00' 109
in this form:
select * from TABID left outer join TABA on (id) left outer join TABB on TABB.id = TABID.id and TABA.t = TABB.t
So, basically, all the rows from table TABID joined with both table TABA and TABB. The problem is that some times TABB doesn't have the "t" values TABA has, and some other times TABA doesn't have the "t" values TABB has.
So I would like an output like:
id, TABA.t, a, TABB.t, b
1 '2009-02-13 00:00:00' 10'2009-02-13 00:00:00' 90
1 NULL NULL '2009-02-13 01:00:00' 109
1 '2009-02-13 02:00:00' 19 NULL NULL
How can I do it?
Passa a Yahoo! Mail.
La webmail che ti offre GRATIS spazio illimitato,
antispam e messenger integrato.
http://it.mail.yahoo.com/
From | Date | Subject | |
---|---|---|---|
Next Message | hendra kusuma | 2009-02-16 08:21:20 | ask: select right(column) ??? |
Previous Message | Tino Wildenhain | 2009-02-16 07:10:27 | Re: Running untrusted sql safely? |