Union instead of Outer Join - Mailing list pgsql-sql

From Unnikrishnan Menon
Subject Union instead of Outer Join
Date
Msg-id 00d101c19f6d$8eba7300$e90aa8c0@UNNIKRISHNAN
Whole thread Raw
Responses Re: Union instead of Outer Join
Re: Union instead of Outer Join
List pgsql-sql
Hi,
 
I have this query in oracle which I'am trying to port to PostgreSQL :
 
Select
    item_code, nvl(user_id,' ') as user_id
from
    item_list L, User_detail B, User_detail S
where
    L.user_id = S.User_id and
    L.other_userid = B.user_id(+) and
    L.item_code = 1234;
 
This query gives me 1 row as result. L.other_userid could be null.
 
I try changing the query thus in postgreSQL :
 
Select
    item_code, nvl(user_id,' ') as user_id
from
    item_list L, User_detail B, User_detail S
where
    L.user_id = S.User_id and
    L.other_userid = B.user_id and
    L.item_code = 1234
Union
Select
    item_code, nvl(user_id,' ') as user_id
from
    item_list L, User_detail B, User_detail S
where
    L.user_id = S.User_id and
    L.item_code = 1234 and
    0 = ( Select
                 count(*)
            from
                 listed_items L, user_detail B, user_detail S
            where
                L.other_userid = B.user_id);
 
The above query does not return any row. Where could I be going wrong?
 
Any help would be appreciated.
 
Thanx in advance
 
Unni

pgsql-sql by date:

Previous
From: Jeff Eckermann
Date:
Subject: Re: Pattern Matching on Columns
Next
From: Jeff Eckermann
Date:
Subject: Re: Union instead of Outer Join