Re: Extraordinary Full Join - Mailing list pgsql-sql

From Josh Berkus
Subject Re: Extraordinary Full Join
Date
Msg-id 200304061005.58820.josh@agliodbs.com
Whole thread Raw
In response to Extraordinary Full Join  ("CN" <cnliou9@fastmail.fm>)
Responses Re: Extraordinary Full Join  ("CN" <cnliou9@fastmail.fm>)
List pgsql-sql
CN:

> Even better, if possible, "sort" book and hobby column descendently to
> fill up null columns:
>
>  id | name |  book  | hobby
> ----+------+--------+-------
>  m1 | John | book1  |hobby1
>  m1 | John | book2  |hobby2
>
> What is the better-have SQL to produce the last furnished list?

You'll need to add an "sort_no" column to both tbook and thobby, and ensure
somehow that both tables have the exact same sequence of sort numbers.  Then
you can:

select tmaster.id, tmaster.name, tbook.book, thobby.hobby
from tmaster, tbook, thobbby
where tmaster.id = tbook.id and tmaster.id = thobby.idand tbook.sort_no = thobby.sort_no
order by name, tbook.sort_no

There would also be ways for you to account for having a different number of
books or hobbies, but that would be a much more complex query.


--
-Josh BerkusAglio Database SolutionsSan Francisco



pgsql-sql by date:

Previous
From: "Hanan Harush"
Date:
Subject: UNSCRIBE
Next
From: Charles McClain
Date:
Subject: Unsubscribe