| From: | Tim Tassonis <timtas(at)cubic(dot)ch> | 
|---|---|
| To: | pgsql-general(at)postgresql(dot)org | 
| Subject: | Tricky join question | 
| Date: | 2006-12-22 11:12:06 | 
| Message-ID: | 458BBD86.5030508@cubic.ch | 
| Views: | Whole Thread | Raw Message | Download mbox | Resend email | 
| Thread: | |
| Lists: | pgsql-general | 
Hi all
I have a join problem that seems to be too difficult for me to solve:
I have:
table person
	id          integer,
	name        varchar(32)
data:
1,"Jack"
2,"Jill"
3,"Bob"
table course
	id         integer,
	name       varchar(32)
data:
1,"SQL Beginner"
2,"SQL Advanced"
table person_course
	person_id  number,
	course_id  number
data:
(currently empty)
Now, I would like to know for every person the courses they have taken.
In mysql, the following statement:
SELECT c.id, c.name, pc.person_id
FROM  person as p
       left outer join person_course as pc on p.id = pc.person_id
       right outer join course as c on pc.course_id = c.id
where p.id = 2 order by 1;
will get me the following result:
+---+-----------------------------------------+----------+
| id| name                                    | person_id|
+---+-----------------------------------------+----------+
| 1 | SQL Beginner                            |          |
| 2 | SQL Advanced                            |          |
+---+-----------------------------------------+----------+
Can I get Postgres to give me the same result somehow? The above 
statement will return nothing at all under postgres.
Bye
Tim
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Filip Rembiałkowski | 2006-12-22 11:12:33 | Re: Unable to start server - winxp | 
| Previous Message | Tarabas (Manuel Rorarius) | 2006-12-22 10:55:30 | Tsearch2 default locale on postgres 8.2 |