| From: | Martijn van Oosterhout <kleptog(at)svana(dot)org> |
|---|---|
| To: | Tim Tassonis <timtas(at)cubic(dot)ch> |
| Cc: | "A(dot) Kretschmer" <andreas(dot)kretschmer(at)schollglas(dot)com>, pgsql-general(at)postgresql(dot)org |
| Subject: | Re: Tricky join question |
| Date: | 2006-12-22 14:19:38 |
| Message-ID: | 20061222141938.GC32471@svana.org |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-general |
Hi,
Without restriction you're getting:
On Fri, Dec 22, 2006 at 02:55:56PM +0100, Tim Tassonis wrote:
> +---+-----------------------------------------+------------+
> | id| name | person_id |
> +---+-----------------------------------------+------------+
> | 1 | SQL Beginner | 1 |
> | 1 | SQL Beginner | |
> | 1 | SQL Beginner | 3 |
> | 2 | SQL Advanced | |
> | 2 | SQL Advanced | |
> | 2 | SQL Advanced | 3 |
> +---+-----------------------------------------+------------+
There are no rows in the table with person_id=2, so PostgreSQL is
returning the correct result (no rows). Seems like a bug in MySQL.
> In mysql, you get this with the following clause:
>
> 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
> order by 1;
I think what you want is to apply to restriction on person earlier,
maybe:
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 and p.id = 2)
right outer join course as c on pc.course_id = c.id
order by 1;
Hope this helps,
--
Martijn van Oosterhout <kleptog(at)svana(dot)org> http://svana.org/kleptog/
> From each according to his ability. To each according to his ability to litigate.
| From | Date | Subject | |
|---|---|---|---|
| Next Message | brian | 2006-12-22 14:21:11 | Re: Tricky join question |
| Previous Message | Tim Tassonis | 2006-12-22 13:55:56 | Re: Tricky join question |