From: | Joost Kraaijeveld <J(dot)Kraaijeveld(at)Askesis(dot)nl> |
---|---|
To: | pgsql-sql(at)postgresql(dot)org |
Subject: | Can I do this smarter? |
Date: | 2006-07-14 03:41:28 |
Message-ID: | 1152848488.6045.13.camel@localhost |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
I have three tables: customers, salesorders and invoices. Customers have
salesorders and salesorders have invoices ( child tables have foreign
key columns to their parent).
I want to get a list of all invoices with their customers. This what I
came up with:
select
invoices.objectid,
invoices.invoicenumber,
invoices.invoicedate,
(select customer from salesorders where objectid = invoices.salesorderobjectid),
(select customernumber from customers where objectid = (select customer from salesorders where objectid = invoices.salesorderobjectid)),
(select lastname from customers where objectid = (select customer from salesorders where objectid = invoices.salesorderobjectid))
from invoices
Can I do this smarter as the three subselects select the same customer three times and I would think that 1 time is enough?
TIA
--
Groeten,
Joost Kraaijeveld
Askesis B.V.
Molukkenstraat 14
6524NB Nijmegen
tel: 024-3888063 / 06-51855277
fax: 024-3608416
web: www.askesis.nl
From | Date | Subject | |
---|---|---|---|
Next Message | Aaron Bono | 2006-07-14 03:52:39 | Re: Can I do this smarter? |
Previous Message | Aaron Bono | 2006-07-14 03:34:28 | Re: Trigger, record "old" is not assigned yet |