Extraordinary Full Join - Mailing list pgsql-sql

From CN
Subject Extraordinary Full Join
Date
Msg-id 20030406055017.6E7054FDFB@smtp.us2.messagingengine.com
Whole thread Raw
Responses Re: Extraordinary Full Join  (Josh Berkus <josh@agliodbs.com>)
List pgsql-sql
Hello! postgreSQL lovers,

Master table tmaster has 2 childern tables tbook and thobby.

CREATE TABLE tmaster (id TEXT,name TEXT);
CREATE TABLE tbook (id TEXT, book TEXT);
CREATE TABLE thobby (id TEXT, hobby TEXT);

INSERT INTO tmaster VALUES ('m1','John');
INSERT INTO tmaster VALUES ('m2','Mary');

INSERT INTO tbook VALUES ('m1','book1');
INSERT INTO tbook VALUES ('m1','book2');

INSERT INTO thobby VALUES ('m1','hobby1');
INSERT INTO thobby VALUES ('m1','hobby2');

I want to list John's books and hobbies in one table:
id | name |  book  | hobby
----+------+--------+-------m1 | John | book1  |m1 | John | book2  |m1 | John |        |hobby1m1 | John |
|hobby2

or
id | name |  book  | hobby
----+------+--------+-------m1 | John |        |hobby1m1 | John |        |hobby2m1 | John | book1  |m1 | John | book2
|

or
id | name |  book  | hobby
----+------+--------+-------m1 | John |        |hobby1m1 | John | book1  |m1 | John |        |hobby2m1 | John | book2
|

etc.

What is the SQL to make any one of above resuts?

Even better, if possible, "sort" book and hobby column descendently to
fill up null columns:
id | name |  book  | hobby
----+------+--------+-------m1 | John | book1  |hobby1m1 | John | book2  |hobby2

What is the better-have SQL to produce the last furnished list?

TIA

CN

-- 
http://www.fastmail.fm - Choose from over 50 domains or use your own



pgsql-sql by date:

Previous
From: "CIC mail"
Date:
Subject: Re: unsubscribe
Next
From: "Hanan Harush"
Date:
Subject: UNSCRIBE