Extraordinary Full Join

From: "CN" <cnliou9(at)fastmail(dot)fm>
To: pgsql-sql(at)postgresql(dot)org
Subject: Extraordinary Full Join
Date: 2003-04-06 05:50:17
Message-ID: 20030406055017.6E7054FDFB@smtp.us2.messagingengine.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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 | |hobby1
m1 | John | |hobby2

or

id | name | book | hobby
----+------+--------+-------
m1 | John | |hobby1
m1 | John | |hobby2
m1 | John | book1 |
m1 | John | book2 |

or

id | name | book | hobby
----+------+--------+-------
m1 | John | |hobby1
m1 | John | book1 |
m1 | John | |hobby2
m1 | 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 |hobby1
m1 | 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

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Hanan Harush 2003-04-06 06:04:45 UNSCRIBE
Previous Message CIC mail 2003-04-05 20:48:58 Re: unsubscribe