Oracle outer join on multiple tables throws error
Hi ,
We are using ansi joins with outer joins on multiple tables in oracle 9i.
Now these queries have to be used in Oracle8i.
Since Oracle8i does not support ansi sql we are replacing the ansi sql queries with the oracle joins.
On trying the same we found that the following query
select *from tab1 a, tab2 b, tab3 c where a.c1 = b.col1(+) and c.c2 = b.col2 (+)
throws the error
ORA-01417: a table may be outer joined to at most one other table.
Is there a way to simulate this query without using the outer joins on multiple tables?
thanks
Try writing the query in this form:
select * from
(select t1.col1, t1.col2
from schema.table1 t1, schema.table2 t2
where t1.col1 = t2.col1(+)) t4,
schema.table3 t3 where t4.col2 = t3.col2(+)
In the subquery, you will have to list all the columns you want to see, and you will need to provide unique aliases for any columns with duplicate names. I tested this on 9i, and don't have an 8i system to work with, so I hope this helps.
Similar Messages
-
Left outer join using multiple table
Hi,
I am trying to use left outer join with multiple tables , the join condition will be based on PERNR and BEGDA & ENDA for each infotype in selection screen.
select pa00~pernr pa00~begda pa00~endda pa00~massn pa00~massg pa00~stat2 pa00~aedtm pa00~uname
pa01~begda pa01~endda pa01~bukrs pa01~persg pa01~persk pa01~mstbr pa01~ename pa01~aedtm pa01~uname
pa02~begda pa02~endda pa02~nachn pa02~vorna pa02~midnm pa02~aedtm pa02~uname
pa016~begda pa016~endda pa016~cttyp pa016~aedtm pa016~uname
into CORRESPONDING FIELDS OF TABLE i_pall
from ( PA0000 as pa00 left OUTER JOIN pa0001 as pa01 on pa00~pernr = pa01~pernr )
left OUTER JOIN pa0002 as pa02 on pa00~pernr eq pa02~pernr )
left OUTER JOIN pa0016 as pa016 on pa00~pernr eq pa016~pernr )
where pa00~pernr in S_pernr
AND pa00~begda in s_bg0000
and pa00~endda in s_nd0000.
but this fails to fetch the value of begda enda from each pa0000,pa0001,pa0002,pa0016.
Please help!
MonirulWhy don't you use the standard logical database PNPCE and then Provide statement?
-
Hi All,
I need to create multiple outer join in Discoverer.
My requirements is like this
I have a report where in I show the sales of components. I have Year as page item in Discoverer cross tab.
I have 2 years in my year table, 1999 and 2000
in the components table I have 3 components, X, Y, Z
In the fact table, I have 5 records as below
YEAR PRODUCT AMOUNT
1999 X 100
1999 Y 200
1999 Z 300
2000 X 400
2000 Y 500
Now with this data, when I create a cross tab with year as page item, I get the following output on selecting 1999 as year in page item,
component Amount SUM
X $100
Y $200
Z $300
similarly when I get report for 2000 it will be as follows
component Amount SUM
X $400
Y $500
Now I want some way to get a report as below for 2000 and similar cases
component Amount SUM
X 400
Y 500
Z 0
Can some body help me??
Thanks,Hi Mrutyunjay,
If you keep the query as described by Csaba but leave out time_period.year from the SELECT and GROUP BY list. In addition, replace the SUM(...) function with the following expression.
SUM (CASE WHEN <condition> THEN fact_tab.amount ELSE 0 END)
Where <condition> will be along the lines of 'time_period.year = 1999'.
This will give you the result you require.
Do be aware that this will force Oracle to do a full scan on the fact_tab table. This may render the solution unworkable.
Cheers,
denty. -
Outer joins across multiple databases
I'm trying to join three tables: 2 from data warehouse and 1 from Siebel database in OBIEE. I create the physical and logical joins (no errors or warnings). The model looks like this: Account Address (table 1) -> Account (table 2) -> Siebel Customer Data (table 3)
I create two queries in Answers:
(1) Account.Number and Siebel.Address (the query works)
(2) Account Address.Zip, Account.Number, and Siebel.Address (the query gets the following error):
State: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error has occurred. [nQSError: 42019] Join condition, D901.c3 <> 0, contains predicates that are currently not supported for outer joins across multiple databases. (HY000)
Can someone help me understand why the join between the two databases works for the first query but when I add a second table it fails?
thanks...Either you can link the Oracle DB into Access (by using File/Get External Data/Link Tables)
or you have to simulate the join in Java by doing two separate queries and looping through the results. -
We are experiencing an unpredictable error in a simple form and have
experimented it in different scenarios it behaves in the same way.
The problem description is as under:
We are using "Join of Multiple Tables" feature of Developer-6i. In our
forms there are two tables e.g. Emp and Dept. We have set all the
properties requiered to do this job inluding:
1. "Query Data Source Name" is set to Emp,Dept.
2. "Where Cluase" is set to Emp.Deptno = Dept.Deptno
3. "DML Target Name" is set to EMP.
4. Manullay created the columns for Dept.Dname.
5. Set the Query-Only Property to Yes.
6. Set the Primary Key Property to Yes for Empno
When we execute this form it performs properly with the normal operations.
It inserts, updates and delete records properly But in the scenario e.g.
when we scroll to 5th or any other record greater this number and
start changing employee name and committing on the each record going
backward. It generates Primary Key Violation errors after updating
4-5 records.
When we locate the error in "Display Error" button it shows the update
statement as "UPDATE EMP SET WHERE ROWID=:1" and there is no "Field=Value"
cluase in the UPDATE statement.Hi, Mahesh,
So you want only 1 row of output for each distinct combination of currentpress and lastpcirim? That sounds like a job for GROUP BY.
And you want that row to contain a delimited list of all the different typidcontainers? That sounds like a job for the aggregate LISTAGG function.
WITH joined_data AS
SELECT DISTINCT
mst.curepress, mst.lastpcirim, inf.typeidcontainer
FROM betmaster mst
LEFT JOIN betinfo inf ON TRIM (mst.curepress) = SUBSTR ( TRIM (inf.currentpress)
, 1
, 3
SELECT curepress, lastpcirim
, LISTAGG (typeidcontainer, ', ')
WITHIN GROUP (ORDER BY typeidcontainer) AS container_list
FROM joined_data
GROUP BY curepress, lastpcirim
Unfortunately, you can't say LISTAGG (DISTINCT ...), so you still have to get the distinct containers the way you're already doing it. (Notice that the sub-query is just what you posted.)
Thanks for posting the CREATE TABLE and INSERT statements; that's very helpful. Don't forget to say which version of Oracle you're using. LISTAGG was new in Oracle 11.2.
Why not add CHECK constraints (and maybe triggers) to your tables, so that curepress and currentpress are not stored with leading or trailing spaces? Then you wouldn't need to use TRIM in queries like this, and your code would be simpler and more efficient. -
Maximum number of tables that can be outer joined with one table in a query
Hi All,
Iam new to sql, so can you please let me know What is the maximum number of tables that can be outer joined with one table in a query?
Thanks,
Srinisrinu2 wrote:
Iam new to sql, so can you please let me know What is the maximum number of tables that can be outer joined with one table in a query?
There is no limit to the number of tables you can outer join as long as you join them correctly.
SQL> with a as
2 (
3 select 1 id, 2 b_key, 3 c_key from dual union all
4 select 2 id, 1 b_key, 4 c_key from dual union all
5 select 3 id, 3 b_key, 1 c_key from dual union all
6 select 4 id, 4 b_key, 2 c_key from dual
7 ),
8 b as
9 (
10 select 1 id, 1 c_key2 from dual union all
11 select 2 id, 5 c_key2 from dual union all
12 select 3 id, 3 c_key2 from dual union all
13 select 4 id, 2 c_key2 from dual
14 ),
15 c as
16 (
17 select 1 key1, 1 key2, '1-1' dta from dual union all
18 select 1 key1, 2 key2, '1-2' dta from dual union all
19 select 1 key1, 3 key2, '1-3' dta from dual union all
20 select 1 key1, 4 key2, '1-4' dta from dual union all
21 select 2 key1, 1 key2, '2-1' dta from dual union all
22 select 2 key1, 2 key2, '2-2' dta from dual union all
23 select 2 key1, 3 key2, '2-3' dta from dual union all
24 select 2 key1, 4 key2, '2-4' dta from dual union all
25 select 3 key1, 1 key2, '3-1' dta from dual union all
26 select 3 key1, 2 key2, '3-2' dta from dual union all
27 select 3 key1, 3 key2, '3-3' dta from dual union all
28 select 3 key1, 4 key2, '3-4' dta from dual union all
29 select 4 key1, 1 key2, '4-1' dta from dual union all
30 select 4 key1, 2 key2, '4-2' dta from dual union all
31 select 4 key1, 3 key2, '4-3' dta from dual union all
32 select 4 key1, 4 key2, '4-4' dta from dual
33 )
34 select d.a_id, d.b_id, c.key1 as c_key1, c.key2 as c_key3, c.dta
35 from
36 c,
37 (
38 select
39 a.id as a_id, b.id as b_id, a.c_key, b.c_key2
40 from a, b
41 where a.b_key = b.id
42 ) d
43 where d.c_key = c.key1 (+)
44 and d.c_key2 = c.key2 (+);
A_ID B_ID C_KEY1 C_KEY3 DTA
3 3 1 3 1-3
4 4 2 2 2-2
2 1 4 1 4-1
1 2
SQL> -
How to use outer join on 3 tables
how to use outer join on 3 tables
say tables are mkpf,lips and vbrp
mkpf-xblnr = lips-vbeln
lips-vbeln = vbrp-vgbelrefer following querry
select a~bukrs
a~anln1
a~ord42
a~ord43
b~afabe
b~ndabj
b~kaafa
b~aafag
c~kostl
d~afasl
d~ndjar
d~ndper
into corresponding fields of table gt_master
from ( ( anla as a inner join anlc as b
on abukrs = bbukrs
and aanln1 = banln1
and aanln2 = banln2 )
inner join anlz as c
on abukrs = cbukrs
and aanln1 = canln1
and aanln2 = canln2 )
inner join anlb as d
on abukrs = dbukrs
and aanln1 = danln1
and aanln2 = danln2
where a~bukrs in s_comp. -
Case statement resulting into Left outer join with other tables
Hi All ,
I am facing a stuation where a Case statement on one of the logical columns in Answers is resulting into a left outer join with a table in the query.
If we remove the case stmt, the table is not being acessed.
The case stmt is a simple one and no other logical column is being accessed in the case stmt.
Please advice .
Thanks.Hi Sai,
No ..we dont have any left outer join ...its just that I am selecting measure from F1 which has a confimred dimension D1 with F2.Now when I dont have case stmt on measure from F1(Case stmt is something like : CASE WHEN "- P table"."P Column" = 'Y' THEN 'Right' ELSE 'Wrong' END), then it doesnt query F2.
However as soon as I introduce the case stmt ,the query creates a left outer join with F2.
Thanks. -
Outer Join for 2 Tables?
Hi,
i have 3 Tables, one is the "main" table.
Table1
Col1
Col2
Col3
Table2
Col2
Col4
Col5
Table3
Col4
Col6
Now i want all hits from Table 1, all outer join hits from table 2 and the regarding rows from table 3.
The join from Table1 to Table2 is no problem, but how to add table3?
SELECT *
FROM table1 AS t1
LEFT OUTER JOIN table2 AS t2
ON t2col2 = t1col2
INTO CORRESPONDING FIELDS OF TABLE result
WHERE t1~col1 IN so_col1.Hi,
a right table in an outer join cannot become a part of an inner join or an outer join. So you will have to use some other technique.
meaing table1 connects to table2 with an outer join resulting in all rows table1 and cooresponding if existing from table2, now table2 is the right table it cannot make a join with table3. inner or outer.
regards,
Khusro Habib -
Global temp table throwing error
Hi,
I am trying to create global temp table throwing error
please help
SQL> create global temporary table test_glb as ( select col1 from test1) on commit delete rows;
create global temporary table test_glb as ( select col1 from test1) on commit delete rows
ORA-00933: SQL command not properly ended
Thanks
Rangan SCREATE GLOBAL TEMPORARY TABLE test_glb ON COMMIT DELETE ROWS
AS SELECT * FROM test1;btw I'm assuming you are just using the SELECT statement to copy the definition of test1. Since DDL statements commit, there will be no rows in test_glb after creating it.
Edited by: William Robertson on Feb 23, 2009 7:31 AM -
Oracle OUTER JOIN on more than one table
Hi!
Friends, please help with this urgent problem: How can an outer join be written on more than one table?
An SQL Server query:
SELECT * from a INNER JOIN b on a.id = b.id LEFT OUTER JOIN c ON c.id = a.id AND c.id = b.id
works fine with SQL SERVER
But Oracle query:
SELECT * from a,b,c WHERE a.id = b.id AND a.id = c.id (+) AND b.id = c.id (+)
gives an error: OUTER JOIN cannot be used on more than one table? Why?
I use OracleDriver from classes12.zip to connect to Oracle8i database.
Please, help!The Oracle 8i and later SQL reference reads that the following "join_types" are supported and under this syntax it does not limit the LEFT OUTER JOIN (syntax the same as SQLServer example in original note) to two tables as implied in these notes:
The join_type indicates the kind of join being performed:
Specify INNER to indicate explicitly that an inner join is being performed. This is the default.
Specify RIGHT to indicate a right outer join.
Specify LEFT to indicate a left outer join.
Specify FULL to indicate a full or two-sided outer join. In addition to the inner join, rows from both tables that have not been returned in the result of the inner join will be preserved and extended with nulls.
You can specify the optional OUTER keyword following RIGHT, LEFT, or FULL to explicitly clarify that an outer join is being performed. -
How to use outer join on 2 tables with Oracle 8i
Could anyone tell me the Oracle 8i syntax equivalent to :
select user.name, city.adress, contry.name
from user
left outer join city on (user.rCity = city.code)
left outer join country on (user.rCountry = country.code)
I tried following :
select user.name, city.adress, contry.name
from user, city, contry
where user.rCity (+) = city.code
and user.rCountry (+) = country.code
but displayed following error :
ORA-01417: a table may be outer joined to at most one other table
Thank youLogically I would expect a user to have a city and a country, or not. In that case the outer join should be on the other tables. Making your query:
select user.name, city.adress, country.name
from user, city, country
where user.rCity = city.code (+)
and user.rCountry = country.code (+); -
Outer Joins with multiple conditions - alternatives to UNION?
It is my understanding that Oracle 8i does not directly support mutiple conditions for outer joins. For instance, I'm looking for PEOPLE who may, or may not, be on MEDICATIONS.
All MEDICATIONS are listed with DRUGNAME and DRUGID. There thousand of different drugs. I'm only looking for PEOPLE on either one or two of them (to make it simple) or no drug at all (ignoring all other DRUGS they're on..) IF they are on the DRUG, it's gerts printed.
I'd ideally do a LEFT OUTER JOIN to do this with multiple conditions:
SELECT DISTINCT
PERSON.NAME,
MEDICATION.DRUGNAME,
MEDICATION.DRUGID
FROM
PERSON,
MEDICATION
WHERE
PERSON.ID = MEDICATION.ID (+) AND
(MEDICATION.DRUGID (+) = 632 OR
MEDICATION.DRUGID (+) = 956)
This, of course, is not valid, at least in 8i...
So I've taken the UNION approach:
SELECT DISTINCT
PERSON.NAME,
MEDICATION.DRUGNAME,
MEDICATION.DRUGID
FROM
PERSON,
MEDICATION
WHERE
PERSON.ID = MEDICATION.ID (+) AND
MEDICATION.DRUGID (+) = 632
UNION
SELECT DISTINCT
PERSON.NAME,
MEDICATION.DRUGNAME,
MEDICATION.DRUGID
FROM
PERSON,
MEDICATION
WHERE
PERSON.ID = MEDICATION.ID (+) AND
MEDICATION.DRUGID (+) = 956
This of course, does work, but as I've added more drugs this becomes quite unwieldly and not really sure what this does to performance. (There are also several more joins to other tables, not relevent here.)
In addition, if I import this into Crystal Reports 8.5 (as opposed to the Crystal Query Designer), it refuses to recognize the UNION.
-- Any suggestions for alternative syntax ???
-- Has this been addressed in 9i ???
Thanks,
WillYou could try
select Distinct Person.Name, Med.DrugName, Med.DrugId
from Person,
(select ID, DrugName, DrugId from Medication
where DrugId in (632, 956) ) Med
where Person.ID = Med.ID(+)
SELECT DISTINCT
PERSON.NAME,
MEDICATION.DRUGNAME,
MEDICATION.DRUGID
FROM
PERSON,
MEDICATION
WHERE
PERSON.ID = MEDICATION.ID (+) AND
(MEDICATION.DRUGID (+) = 632 OR
MEDICATION.DRUGID (+) = 956)
This, of course, is not valid, at least in 8i...
So I've taken the UNION approach:
SELECT DISTINCT
PERSON.NAME,
MEDICATION.DRUGNAME,
MEDICATION.DRUGID
FROM
PERSON,
MEDICATION
WHERE
PERSON.ID = MEDICATION.ID (+) AND
MEDICATION.DRUGID (+) = 632
UNION
SELECT DISTINCT
PERSON.NAME,
MEDICATION.DRUGNAME,
MEDICATION.DRUGID
FROM
PERSON,
MEDICATION
WHERE
PERSON.ID = MEDICATION.ID (+) AND
MEDICATION.DRUGID (+) = 956
This of course, does work, but as I've added more drugs this becomes quite unwieldly and not really sure what this does to performance. (There are also several more joins to other tables, not relevent here.)
In addition, if I import this into Crystal Reports 8.5 (as opposed to the Crystal Query Designer), it refuses to recognize the UNION.
-- Any suggestions for alternative syntax ???
-- Has this been addressed in 9i ???
Thanks,
Will -
I am dealing with a nested table (I simplified the case
for purpose of posting):
CREATE TABLE boris_main_tab (
IND_SSN VARCHAR2(9) PRIMARY KEY,
children B_CHILDREN_TBL,
) nested table children stored as....
where B_CHILDREN_TBL is defined like this:
create or replace type b_children_type as object (
child_ssn VARCHAR2(9),
child_first_name VARCHAR2(20),
child_last_name VARCHAR2(20),
child_dob date
create or replace type b_children_tbl as table of b_children_type;
if I want to display person's ssn along with his/her children information I do like this:
SELECT m.ind_ssn, c.child_ssn, c.child_first_name
FROM boris_main_tab m,
TABLE(m.children) c
This is a statement I can find everywhere. But there is a caveat here, they
forgot to mention. This is really an inner join, so I don't get childless
people. Can you, guys, help me with the outer join syntax?
I mean, of course, I found the obvious solution to make this inner join
into a view and then join it with the boris_main_tab again this time using the
regular outer join syntax. But it seems to me there has to be something simplier than that.
But I can't find it. It really hurting me, since I have a few nested table
columsn and people want to see the records where I need to mention a few of
them, sort of like
from boris_main_tab m, TABLE(m.children) c, TABLE(m.spouses) s
where c.child_last_name <> m.spouse.last_name
in cases like this the fact that EACH of these joins is inner join really
hurts the logic.
Respectfully,
BorisHi Borris,
Found the following in the Oracle Documentation under: Oracle8i Application Developer's Guide - Object-Relational Features Release 2 (8.1.6)
2 Managing Oracle Objects / Using Collections / Collection Unnesting
URL: http://www.znow.com/sales/oracle/appdev.816/a76976/adobjmng.htm#1002885
Oracle8i also supports the following syntax to produce outer-join results:
SELECT d.*, e.* FROM depts d, TABLE(d.emps)(+) e;
The (+) indicates that the dependent join between DEPTS and D.EMPS should be NULL-augmented. That is, there > will be rows of DEPTS in the output for which D.EMPS is NULL or empty, with NULL values for columns
corresponding to D.EMPS. -
Hi:
I am attempting to create a view using an outer join on 10 different Oracle tables and I can't seem to get the syntax right because not all of the information that should appear in the VIEW is appearing. Below is the syntax for the VIEW:
CREATE VIEW dwgSearchEngineResults AS
SELECT Drawing.dwgID, Drawing.PMDwgNum, Drawing.Type, Drawing.Title, Drawing.dwgSize,
Drawing.projectNum, Panel_Number.panlnumID, Panel_Number.panlNumber, Discipline.disciplineID,
Discipline.drawingType, Area.areaID, Area.areaNum, Asset_Number.assetnumID, Asset_Number.assetNumber,
Vendor.vendorID, Vendor.Name
FROM AJM.Drawing, AJM.Discipline, AJM.Panel_Number, AJM.Dwg_Panel_Number, AJM.Area,
AJM.Dwg_Area, AJM.Asset_Number, AJM.Dwg_Asset_Number, AJM.Vendor, AJM.Vendor_Drawing
WHERE Drawing.disciplineID = Discipline.disciplineID(+) AND Drawing.dwgID = Dwg_Panel_Number.dwgID(+)
AND Dwg_Panel_Number.panlNumID = Panel_Number.panlNumID(+) AND Drawing.dwgID = Dwg_Area.dwgID(+)
AND Dwg_Area.areaID = Area.areaID(+) AND Drawing.dwgID = Dwg_Asset_Number.dwgID(+)
AND Dwg_Asset_Number.assetnumID = Asset_Number.assetnumID(+) AND Drawing.dwgID = Vendor_Drawing.dwgID(+)
AND Vendor_Drawing.vendorID = Vendor.vendorID(+);I attempted to Bold the main tables for you, but the tags don't seem to be working. So the tables that you see in the FROM clause with the tags are the main tables and the rest are bridge tables that take away the many - to - many relationship between the main tables.
As I said earlier, the outer join isn't working right because for example, I know for sure that there area 3 Vendor names in the Vendor table. However, when I select the vendor name from the VIEW, none of the names appear. It should be noted that the none of the dwgID's are in the Vendor_Drawing table since none of the drawings are Vendor drawings. Is that why the 3 vendor names don't appear in the VIEW? Also, I know there are 2 area numbers in the Area table. Again, when I select the area number from the VIEW, I only get 1 area number that displays, and that's the one that the dwgID and the areaID match in the Dwg_Area table.
This is a search engine that I'm developing and I thought it would be easier to write a VIEW since the users can search for different parameters from either of these tables. I know this is pretty complex, but can someone please help me.Oops, that was meant to be a cross-post notification...
Cross post:
http://forum.java.sun.com/thread.jsp?forum=48&thread=502319&start=0&range=15#2376543
Maybe you are looking for
-
Thunderbolt Daisy Chain to a DisplayPort Monitor (Dell 2713HM)?
I have a Mac mini (2011) that supports my Dell monitor (2713HM 27'') at its maximum reslution of 2560x1440 only through a Thunderbolt to Mini-Displayport cable. As this Mac has only Thunderbolt as a fast connection for backup drives I have to add a T
-
Its superslow in Facebook and wont allow me to post links until I do it twice..........Ive been having to use Chrome :( I want the old Firefox better the toolbar was better and everything about it just worked better and easier!!!
-
SAML Implementation for External third party portal
Hi Experts I am trying to configure external third party portal to SAP Portal using SAML. Has anyone done that before? I would appreciate if someone can provide details of this kind of implementation as Idendity provider and destination is on their s
-
CD Drive not working since last set of updates
Anyone else have the problem? It affected my CD drive on my iMac G5...the drive scans and scans blank or recorded CDs then after a while spits them out. I guess it could be something wrong or dirty with the drive, but was suspicious since ih just hap
-
I get error every time I try to update my iTunes to 11.5.2 on my mac mini w/lion
I get an error message every time I try to update ITunes on my mac mini 10.8.3 while connected to the ap store....help?