views:

41

answers:

2

We had the following query in sql server:

SELECT b.columnB, 
     b.displayed_name AS displayName, 
     c.type_cd, 
     c.type_desc, 
     b.month_desc AS month
FROM table1 a, table2 b, table3 c
WHERE b.region_code *= a.columnA
        AND c.program_type_cd *= a.program_type_cd

which, in oracle, got converted to:

SELECT b.columnB,
       b.displayed_name displayName,
       c.type_cd,
       c.type_desc,
       b.month_desc month
FROM   table1 a,
       table2 b,
       table3 c
WHERE b.columnB = a.columnA(+)
       AND c.type_cd = a.type_cd(+)

But while running this in oracle we get an error

"a table must be outer joined to at most one other table"

whats the best way to fix this and keep the same logic as sql server?

+1  A: 

Try this once:

SELECT b.columnB,
       b.displayed_name displayName,
       c.type_cd,
       c.type_desc,
       b.month_desc month
FROM   table1 a
       LEFT JOIN table2 b ON b.columnB = a.columnA
       LEFT JOIN tablec c ON c.type_cd = a.type_cd
Eric Petroelje
if *= and LEFT JOIN do the same thing then I'll def go for LEFT JOIN. this is why I hate annotations in programming also. thanks
Omnipresent
Actually I don't think this does the same thing as the original query: the original was a left join from b to a, and simultaneously from c to a, which is why Oracle complained. The rewritten query is a left join from a to b and a to c, which would have been =* instead of *= in the original query.
William Rose
so how should it be written in oracle?
Omnipresent
A: 

Why is table1 listed as an OUTER JOIN if you're not returning any data from it? It seems like you'd want table1 to be an inner join to table2, and then do an OUTER between 2 and 3. Like this:

SELECT b.columnB,
       b.displayed_name displayName,
       c.type_cd,
       c.type_desc,
       b.month_desc month
FROM   table1 a,
       table2 b,
       table3 c
WHERE b.columnB = a.columnA
       AND c.type_cd = a.type_cd(+)

On another note, I'd recommond switching to ANSI joins (as in Eric's example) - they're much easier to read, though functionally, they're the same thing and are executed the exact same way.

rwmnau
it is listed because the original query was long and had way more columns. I shortened it for this specific question.
Omnipresent