Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Mailing Lists -> Oracle-L -> RE: query problem (left outer join)
Maybe I don't understand the query, but is this the results you are expecting (this query assumes that TAB3.NM is a NOT NULL column) If my query isn't right, perhaps you could show what results you would expect from the test data and that would help people smarter than me write the query you need.
SELECT
accmap.id_acc as id_acc,
av.c_firstname as firstname, av.c_lastname as lastname, av.c_middleinitial as middleinitial, av.c_zip as zip
Here is my test data and the query results:
create table tab1 (id_acc number) ;
create table tab2 (id_acc number, c_contacttype number,
c_firstname varchar2 (10), c_lastname varchar2 (10),
c_middleinitial varchar2 (1), c_zip varchar2 (5)) ;
create table tab3 (id number, nm varchar2 (7) not null) ;
insert into tab1 (id_acc) values (1) ; insert into tab1 (id_acc) values (4) ; insert into tab1 (id_acc) values (345) ;insert into tab2
select 345, 3, 'ULYSSES', 'GRANT', 'S', '34502' from dual ; insert into tab3 (id, nm) values (1, 'abc') ; insert into tab3 (id, nm) values (2, 'bill-to') ;commit ;
SQL> SELECT
2 accmap.id_acc as id_acc,
3 av.c_firstname as firstname, 4 av.c_lastname as lastname, 5 av.c_middleinitial as middleinitial, 6 av.c_zip as zip 7 FROM 8 Tab1 accmap, tab2 av, tab3 ed 9 where 10 accmap.id_acc in (4, 345) 11 and accmap.id_acc = av.id_acc (+) 12 and av.c_contacttype = ed.id (+) 13 and (ed.nm is null or ed.nm = 'bill-to') ;
ID_ACC FIRSTNAME LASTNAME M ZIP
--------- ---------- ---------- - -----
345 HERBERT HOOVER J 34501 345 ULYSSES GRANT S 34502 4
-----Message d'origine-----
De : oracle-l-bounce_at_freelists.org [mailto:oracle-l-bounce_at_freelists.org] De la part de Harvinder Singh
Envoyé : lundi, 2. octobre 2006 10:15
À : Nigel Thomas; oracle-l
Objet : RE: query problem (left outer join)
This will change the semantic of the query, we need to get all records of accmap and then where value of tab2 does not matches left outer join will insert nulls, but if I use tab3 as inner join then that will remove still return data from tab2
-----Original Message-----
From: Nigel Thomas [mailto:nigel_at_preferisco.com]
Sent: Monday, October 02, 2006 11:05 AM
To: Harvinder Singh; oracle-l
Subject: Re: query problem (left outer join)
Harvinder
Include your tab3 BEFORE the outer join. Then no need for a subquery, no need to resolve a forward reference:
SELECT
accmap.id_acc as id_acc,
av.c_firstname as firstname, av.c_lastname as lastname, av.c_middleinitial as middleinitial, av.c_zip as zip
Regards Nigel
--
http://www.freelists.org/webpage/oracle-l
--
http://www.freelists.org/webpage/oracle-l
Received on Mon Oct 02 2006 - 13:56:35 CDT
![]() |
![]() |