From: | Josh Berkus <josh(at)agliodbs(dot)com> |
---|---|
To: | "CN" <cnliou9(at)fastmail(dot)fm>, pgsql-sql(at)postgresql(dot)org |
Subject: | Re: Extraordinary Full Join |
Date: | 2003-04-06 17:05:58 |
Message-ID: | 200304061005.58820.josh@agliodbs.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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.id
and 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 Berkus
Aglio Database Solutions
San Francisco
From | Date | Subject | |
---|---|---|---|
Next Message | Charles McClain | 2003-04-06 18:37:15 | Unsubscribe |
Previous Message | Hanan Harush | 2003-04-06 06:04:45 | UNSCRIBE |