Oracle: fixing an outer join on subquery...


 
Thread Tools Search this Thread
Top Forums Programming Oracle: fixing an outer join on subquery...
# 1  
Old 03-16-2009
Oracle: fixing an outer join on subquery...

I have a stored procedure that is failing. The current query behind it is:
Code:
SELECT DISTINCT
    <many, many values>
FROM
     table1    
	LEFT OUTER JOIN table2 ON
	   (table2.key = 
              (select max (table2.key) from table2
                 where table2.key = table1.key) or
                   table2.key is null)
	INNER JOIN table3 ON
	        table1.key = table3.key
	INNER JOIN view1 ON 
		table3.key = view1.key
	INNER JOIN table4 ON
	        view1.key = table4.key
	INNER JOIN table5 groupdesc ON
		table5.key = groupdesc.key
	INNER JOIN table6 ON
	       	table3.key = table6.key
	INNER JOIN table5 methoddesc ON
        	table6.key = methoddesc.key
	INNER JOIN table7 ON
	       	view1.key = table7.key
	INNER JOIN table8 ON
	       	table8.key = table7.key
	INNER JOIN table5 iddesc ON
        	table8.key = iddesc.key
	LEFT OUTER JOIN view2 ON
		view2.key = view1.key
	INNER JOIN table9 ON
		(table9.key = table1.key)
	INNER JOIN table10 ON
		(table10.key = view1.key)
WHERE
        <many, many conditions>;

This fails because of the left outer join on a subquery. I have tried to get around this in several ways, without much success. One that I was certain should work is to replace the subquery with an inline view, like so:

Code:
SELECT DISTINCT
      <many, many values>
FROM
    (select MAX(table2.key) AS key from table2,table1
          where table2.key = table1.key) VW,
     table1
  LEFT OUTER JOIN table2 ON
	   (table2.key = VW.key or table2.key is null)
	INNER JOIN table3 ON
	        table1.key = table3.key
	INNER JOIN view1 ON 
		table3.key = view1.key
	INNER JOIN table4 ON
	        view1.key = table4.key
	INNER JOIN table5 groupdesc ON
		table5.key = groupdesc.key
	INNER JOIN table6 ON
	       	table3.key = table6.key
	INNER JOIN table5 methoddesc ON
        	table6.key = methoddesc.key
	INNER JOIN table7 ON
	       	view1.key = table7.key
	INNER JOIN table8 ON
	       	table8.key = table7.key
	INNER JOIN table5 iddesc ON
        	table8.key = iddesc.key
	LEFT OUTER JOIN view2 ON
		view2.key = view1.key
	INNER JOIN table9 ON
		(table9.key = table1.key)
	INNER JOIN table10 ON
		(table10.key = view1.key)
WHERE
        <many, many conditions>;

This, however, results in a ORA-00904 (VW.KEY an invalid identifier) on the red line. Am I going about this the right way? If so, what am I doing wrong?
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Programming

Oracle 11g optimizer best join order question

Hi team Optimizer max permutations and search limit are set to 3.5 million and 10 respectively.The parameter instruct optimizer to evaluate up to 3.5 million permutations for max 10 table joins I have query with 9 tables joined. How many combinations will optimizer perform to find best... (1 Reply)
Discussion started by: Perlbaby
1 Replies

2. UNIX for Dummies Questions & Answers

UNIX outer join

Hello.. I am trying to join two files of about 7000 records. it looked quite straight forward when i began, but i'm not getting the desired output. here is what i'm trying to do: cat xxx item,So,Mo,Tu aaa,1,1,1 bbb,1,1,4 ccc,1,1,0 ddd,1,1,1 cat yyy item,Tu,We aaa,1,1 bbb,4,0... (7 Replies)
Discussion started by: wanderingmind16
7 Replies

3. Shell Programming and Scripting

Break the outer loop

Hi I'm comparing same files names which are in different folders . The first for loop for the files in DAY1 folder and the second for loop for the files in DAY2 folder . the first IF condition is for checking whether the file names are equal the second If condtion is for checking the... (4 Replies)
Discussion started by: smile689
4 Replies

4. UNIX for Dummies Questions & Answers

How to use the the join command to join multiple files by a common column

Hi, I have 20 tab delimited text files that have a common column (column 1). The files are named GSM1.txt through GSM20.txt. Each file has 3 columns (2 other columns in addition to the first common column). I want to write a script to join the files by the first common column so that in the... (5 Replies)
Discussion started by: evelibertine
5 Replies

5. Programming

Help with Oracle SQL Developer - Subquery & Join will not work.

Greetings all, Hopefully there is someone out there on this forum who can help with this Oracle SQL Developer issue I have. Here is the code: CREATE OR REPLACE VIEW SALES_OVER_30000_WITH_TOTAL AS SELECT E.FIRST_NAME || ' ' || E.LAST_NAME AS EMPLOYEE_NAME, ... (2 Replies)
Discussion started by: U_C_Dispatj
2 Replies

6. Programming

OUTER join?

Hi, I have a code where it traverses through each record froma table and creates records in another table. I use FOREACH cursor to do this, i'm using another cursor inside the FOREACH to fetch the details of other table. Please suggest me which would be more efficient, as this will run against... (2 Replies)
Discussion started by: dvah
2 Replies

7. UNIX for Dummies Questions & Answers

Join 2 files with multiple columns: awk/grep/join?

Hello, My apologies if this has been posted elsewhere, I have had a look at several threads but I am still confused how to use these functions. I have two files, each with 5 columns: File A: (tab-delimited) PDB CHAIN Start End Fragment 1avq A 171 176 awyfan 1avq A 172 177 wyfany 1c7k A 2 7... (3 Replies)
Discussion started by: InfoSeeker
3 Replies

8. UNIX and Linux Applications

Alternative for slow SQL subquery

Hi -- I have the following SQL query in my UNIX shell script -- but the subquery in the second section is very slow. I know there must be a way to do this with a union or something which would be better. Can anyone offer an alternative to this query? Thanks. select count(*) from ... (2 Replies)
Discussion started by: whoknows
2 Replies

9. Programming

sql,multiple join,outer join issue

example sql: select a.a1,b.b1,c.c1,d.d1,e.e1 from a left outer join b on a.x=b.x left outer join c on b.y=c.y left outer join d on d.z=a.z inner join a.t=e.t I know how single outer or inner join works in sql. But I don't really understand when there are multiple of them. can... (0 Replies)
Discussion started by: robbiezr
0 Replies
Login or Register to Ask a Question