Received: from localhost.localdomain (postgresql.org [64.49.215.8]) by localhost (Postfix) with ESMTP id 8CEB2476E8B for ; Thu, 13 Jun 2002 10:35:07 -0400 (EDT) Received: from mta05ps.bigpond.com (mta05ps.bigpond.com [144.135.25.137]) by postgresql.org (Postfix) with ESMTP id 7855D476DCF for ; Thu, 13 Jun 2002 10:32:58 -0400 (EDT) Received: from hobbes ([144.135.25.87]) by mta05ps.bigpond.com (Netscape Messaging Server 4.15 mta05ps Apr 29 2002 13:22:02) with SMTP id GXNF3100.D9E for ; Fri, 14 Jun 2002 00:33:01 +1000 Received: from CPE-144-136-0-9.vic.bigpond.net.au ([144.136.0.9]) by psmam07.mailsvc.email.bigpond.com(MailRouter V3.0n 119/4193992); 14 Jun 2002 00:33:01 Message-ID: <08da01c212e7$37bf1450$fe00a8c0@hobbes> From: "Dmitri Colebatch" To: References: <08af01c212e4$7a12a180$fe00a8c0@hobbes> Subject: Re: join question - three tables, two with foreign keys to the first Date: Fri, 14 Jun 2002 00:32:59 +1000 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2462.0000 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2462.0000 X-Archive-Number: 200206/171 X-Sequence-Number: 8136 maybe just to qualify, I get this: select emp.name, lv.from_date, lv.to_date, pay.amount from employee as emp left join employee_leave as lv on emp.id = lv.employee_id left join employee_pay as pay on emp.id = pay.employee_id where emp.id = 1; name | from_date | to_date | amount ------+------------+------------+-------- dim | 2002-10-05 | 2002-05-14 | 100 dim | 2002-10-05 | 2002-05-14 | 100 dim | 2002-10-06 | 2002-06-14 | 100 dim | 2002-10-06 | 2002-06-14 | 100 (4 rows) but would expect the results to be name | from_date | to_date | amount ------+------------+------------+-------- dim | 2002-10-05 | 2002-05-14 | (null) dim | 2002-10-05 | 2002-05-14 | (null) dim | (null) | (null) | 100 dim | (null) | (null) | 100 (4 rows) am I missing something? ta again dim ----- Original Message ----- From: "Dmitri Colebatch" To: Sent: Friday, June 14, 2002 12:13 AM Subject: [SQL] join question - three tables, two with foreign keys to the first > hey all, > > here's my situation. three tables: > > create table employee (id integer primary key, name varchar(32)); > create table employee_leave (id integer primary key, employee_id integer, > from_date date, to_date date, constraint emp_leave_fk foreign key > (employee_id) references employee (id)); > create table employee_pay (id integer primary key, employee_id integer, > amount integer, constraint emp_pay_fk foreign key (employee_id) references > employee (id)); > > and some sample data: > > insert into employee (id, name) values (1, 'dim'); > insert into employee_leave (id, employee_id, from_date, to_date) values (2, > 1, '10-05-2002', '14-05-2002'); > insert into employee_leave (id, employee_id, from_date, to_date) values (1, > 1, '10-06-2002', '14-06-2002'); > insert into employee_pay(id, employee_id, amount) values (1, 1, 100); > insert into employee_pay(id, employee_id, amount) values (2, 1, 100); > > and I want to retrieve the information for an employee (all pay, and all > leave) in one query.... here's what I've got > > select emp.name, lv.from_date, lv.to_date, pay.amount > from employee as emp > left outer join employee_leave as lv on emp.id = lv.employee_id > left outer join employee_pay as pay on emp.id = pay.employee_id > where emp.id = 1 > > problem is that I dont get the null values I expect.... I want to be able to > iterate through the resultset and determine if the record is from the leave > table or pay table - but because I dont get null results, I cant.... > > any pointers/suggestions would be welcome. > > cheers > dim > > > > ---------------------------(end of broadcast)--------------------------- > TIP 6: Have you searched our list archives? > > http://archives.postgresql.org >