Re: Join question

From: Paul Lambert <paul(dot)lambert(at)autoledgers(dot)com(dot)au>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: Join question
Date: 2007-07-27 02:18:36
Message-ID: 46A955FC.8000105@autoledgers.com.au
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Phillip Smith wrote:
> Whoops, I forgot the JOIN conditions! Fixed below
>
> -----Original Message-----
> From: Phillip Smith [mailto:phillip(dot)smith(at)weatherbeeta(dot)com(dot)au]
> Sent: Friday, 27 July 2007 11:47
> To: 'pgsql-sql(at)postgresql(dot)org'
> Subject: RE: [SQL] Join question
>
>
> This might give you a starting point if I understand you correctly...
>
> SELECT h.invoice_number,
> h.customer,
> l.item,
> l.amount
> FROM lines AS l
> JOIN headers AS h ON l.invoice_number = h.invoice_number
> UNION
> SELECT h.invoice_number,
> h.customer,
> s.item,
> s.amount
> FROM sundries AS s
> JOIN headers AS h ON s.invoice_number = h.invoice_number
> ORDER BY invoice_number, item
>

Forgot all about union - I had two individual views, one for
invoice+parts, one for invoice+sundries... didn't think of union to
combine the two views together.

Perfect solution, you've done it for me again Phillip, thanks.

--
Paul Lambert
Database Administrator
AutoLedgers

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Tom Lane 2007-07-27 02:49:31 Re: unique index on fields with possible null values
Previous Message Phillip Smith 2007-07-27 01:48:10 Re: Join question