Re: [GENERAL] Tricky join question

2006-12-22 Thread Tim Tassonis
Thanks to you all for your replies. I was able to solve my problem after some more reading in the manual: select c.id, c.name, pc.person_id from person as p cross join course as c left outer join person_course as pc on (p.id = pc.person_id and c.id = pc.course_id) where p.id = 2; A

Re: [GENERAL] Tricky join question

2006-12-22 Thread Andreas Kretschmer
Tim Tassonis <[EMAIL PROTECTED]> schrieb: > This is absolutely not what I want. I want a row for every person and every > course, regardless whether the person has taken the course or not. If the > person has not taken the course, I want a null value in the person id > column: test=# select c

Re: [GENERAL] Tricky join question

2006-12-22 Thread Tom Lane
Tim Tassonis <[EMAIL PROTECTED]> writes: > 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; > wil

Re: [GENERAL] Tricky join question

2006-12-22 Thread brian
Tim Tassonis wrote: Hi Andreas First, you should use referential integrity: I do, that is not the point. It was a simplified data model. Of course I have primary keys and stuff, but they don't affect join behaviour at all. test=# create table person(id int primary key, name text); NOTIC

Re: [GENERAL] Tricky join question

2006-12-22 Thread Martijn van Oosterhout
Hi, Without restriction you're getting: On Fri, Dec 22, 2006 at 02:55:56PM +0100, Tim Tassonis wrote: > +---+-++ > | id| name| person_id | > +---+-++ > | 1

Re: [GENERAL] Tricky join question

2006-12-22 Thread Tim Tassonis
Hi Andreas First, you should use referential integrity: I do, that is not the point. It was a simplified data model. Of course I have primary keys and stuff, but they don't affect join behaviour at all. test=# create table person(id int primary key, name text); NOTICE: CREATE TABLE / PRIMA

Re: [GENERAL] Tricky join question

2006-12-22 Thread A. Kretschmer
am Fri, dem 22.12.2006, um 12:12:06 +0100 mailte Tim Tassonis folgendes: > Hi all > > I have a join problem that seems to be too difficult for me to solve: > > I have: > > table person > id integer, > namevarchar(32) > > data: > > 1,"Jack" > 2,"Jill" > 3,"Bob" >

[GENERAL] Tricky join question

2006-12-22 Thread Tim Tassonis
Hi all I have a join problem that seems to be too difficult for me to solve: I have: table person id integer, namevarchar(32) data: 1,"Jack" 2,"Jill" 3,"Bob" table course id integer, name varchar(32) data: 1,"SQL Beginner" 2,"