Search Postgresql Archives

Tricky join question

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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








[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux