Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Left Outer Join not returning unmatched rows 1

Status
Not open for further replies.

Padre764

Programmer
Jul 30, 2002
10
US
Hello,

I am using Oracle 9.2.0.3. I want to find out what columns exist in one table but don't exist in another table. Here is the SQL:
select a.column_name dim_col
, b.column_name hist_col
from user_tab_columns a left outer join user_tab_columns b
on a.column_name = b.column_name
where a.table_name = 'T_DIM'
and b.table_name = 'T_HIST_DIM'
order by 1

The T_DIM table has 100 columns in it and the T_HIST_DIM table has 40. I was expecting that this query would return 100 rows with NULLs for the hist_col where there were no matches; instead I only got 40 rows. I tried rewriting the query using 8i syntax and got the same results. I have asked several other developers and they all think that I should be getting 100 rows back. What's going wrong?

Thanks, :)
Padre
 
Use inline views so that your where conditions are applied before the join so that they don't remove the records with NULL in the table_name field, too.

...
From (Select * from User_Tab_Columns where table_name='T_DIM') a
Left Join (Select * from User_Tab_Columns where table_name='T_HIST_DIM') b On
...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top