Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

ORA-00918: column ambiguously defined error cannot be avoided automatically

plsql noviceFeb 4 2015 — edited Feb 4 2015

Hello, I'm just wondering for below SQL, why is the optimizer not smart enough to avoid the ORA-00918: column ambiguously defined error:

Sample SQL:

select a.* from table1 a, table2 b

where a.col1 = b.col1

and a.col2 = b.col2

order by col1, col2;

Since I'm only selecting a.*, shouldn't the server automatically knows to order by a.col1, a.col2?

Or even order by b.col1, b.col2 would produce same result due to the equality conditions in the SQL clauses.

Why would Oracle throw the ORA error and not include the above checkings?

Or maybe my above assumptions above are flawed and do not work all the time?

Many thanks.

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 4 2015
Added on Feb 4 2015
6 comments
769 views