SQL - Oracle - Query Runs Successfully, But The Column Name Is Not Available - Stack Overflow
SQL - Oracle - Query Runs Successfully, But The Column Name Is Not Available - Stack Overflow
available
Asked 5 years, 11 months ago Modified 5 years, 11 months ago Viewed 283 times
In our application Oracle(11g and 12C) , I'm facing a weird Issue as below.
When I run the below query in Oracle DB it runs successfully and gives me output.
2
select * from table1 where col1 in (select col2 from table2 ) ;
But when I run the below inner query alone it throws the error:
When I described the table table2, Col2 is not there. The error is expected. But the previous query
executes successfully which is my concern.Could some one explain me this behavior?
Share Improve this question Follow edited Nov 27, 2017 at 12:13 asked Nov 27, 2017 at 11:20
DineshDB Vinoth Karthick
6,038 8 33 49 995 10 29
Always, I repeat always give and use table aliases. You will never run into troubles and won't face such
scenarios: Now run below query again in same DB, I'm sure it will throw some error:
2
select * from table1 a where a.col1 in (select b.col2 from table2 b) ;
Now notice, all I did was give tables aliases. What most probably happening here is that table1 has a
column named 'col2' and sub-query is referencing to that one. That's why it runs fine and doesn't show
any error.
Share Improve this answer Follow answered Nov 27, 2017 at 11:37
Niranjan Rajawat
553 2 9