Skip site navigation (1) Skip section navigation (2)

Peripheral Links

Header And Logo

PostgreSQL
| The world's most advanced open source database.

Site Navigation

Search for
  Advanced Search

Re: Join question



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



Home | Main Index | Thread Index

Privacy Policy | PostgreSQL Archives hosted by Command Prompt, Inc. | Designed by tinysofa
Copyright © 1996 – 2008 PostgreSQL Global Development Group