Re: OUTER JOIN

From: Richard Huxton <dev(at)archonet(dot)com>
To: "Marco Roda" <MarcoRoda(at)amdosoft(dot)com>, <pgsql-sql(at)postgresql(dot)org>
Subject: Re: OUTER JOIN
Date: 2003-04-23 17:55:36
Message-ID: 200304231855.37050.dev@archonet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Thursday 17 Apr 2003 3:21 pm, Marco Roda wrote:
> Hallo,
>
> I need to port some SQL from Oracle to PostgreSQL v7.2, but I am finding
> problems with outer joins.
[snip]
> and here is the SQL for Oracle:
> SELECT ST.id, ST.order_num, ST.from_time, ST.to_time, ST.disabled,
> SD.description
> FROM shift_type ST, shift_desc SD
> WHERE ST.id = SD.shift_type_id(+) AND SD.app_language_id(+) = 2
> ORDER BY ST.order_num
>
> The expected result should be:
> id | order_num | from_time | to_time | disabled | description
> ----+-----------+-----------+----------+----------+-------------
> 1 | 1 | 06:00:00 | 14:00:00 | f |
> 2 | 2 | 14:00:00 | 22:00:00 | f |
> 3 | 3 | 22:00:00 | 06:00:00 | t |
> 6 | 6 | 00:00:00 | 23:00:00 | f | SHIFT_DE
> with description populated with NULL, as app_language_id not found.
>
> It seems that Oracle's outer joins work on the basis the single record,
> while PostgreSQL don't.
> How to do it?

SELECT ST.id, ST.order_num, ST.from_time, ST.to_time, ST.disabled,
SD.description
FROM shift_type ST LEFT JOIN shift_desc SD
ON ST.id=SD.shift_type_id AND SD.app_language_id=2
ORDER BY ST.order_num;

That seems to work. Out of curiosity, what were you trying?

--
Richard Huxton

In response to

  • OUTER JOIN at 2003-04-17 14:21:36 from Marco Roda

Browse pgsql-sql by date

  From Date Subject
Next Message Stephan Szabo 2003-04-23 18:11:25 Re: SQL Reserved words
Previous Message mallah 2003-04-23 17:54:45 Re: Why is seq search preferred here by planner?