Question

I have a trouble querying view in Oracle.

Here is the view (my_cool_view) definition:

SELECT *
  FROM mview1 JOIN
       mview2 USING(col_id) 

where mview1 and mview2 is materialized views. I can't access to definition of this materialized views. I've tried this query:

select r.title from my_cool_view r;

and got ORA-00918: column ambiguously defined error. I got this error for subset of columns in my_cool_view.

If I run this query:

select * from my_cool_view;

all works fine.

You are asking about desc my_cool_view in comments, sorry I can't provide schema information because it's confidential. The only I can say it contains about 80 columns, and only one (col_id) don't cause above error.

Do you have any ideas what is the case and how to fix it?

Thanks in advance.

Sorry for misled you, the first version of question was too bad.

Was it helpful?

Solution

You probably have 2 columns called title from different tables/views that you've joined. If you select * then this will work as the duplicate title columns will get a different alias (like TITLE1). When you explicitly ask for one of the title columns the database needs to know which one you want and thus throws the error.

Just make sure that the title columns have a different alias:

   select EMP.TITLE EMP_TITLE, DEPT.TITLE DEPT_TITLE
   FROM   ...
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top