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


---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to [EMAIL PROTECTED] so that your
message can get through to the mailing list cleanly

Reply via email to