I have the following query:
select * from
(select rownum rnum, p.* from
(select DEPARTMENTS.DEPARTMENT_ID,
DEPARTMENTS.DEPARTMENT_NAME,
DEPARTMENTS.MANAGER_ID,
EMPLOYEES.EMPLOYEE_ID,
EMPLOYEES.FIRST_NAME,
EMPLOYEES.LAST_NAME,
EMPLOYEES.MANAGER_ID,
EMPLOYEES.DEPARTMENT_ID,
EMPLOYEES.DETAILS
from HR.EMPLOYEES
INNER JOIN HR.DEPARTMENTS on
HR.DEPARTMENTS.DEPARTMENT_ID=EMPLOYEES.DEPARTMENT_ID
where EMPLOYEES.EMPLOYEE_ID >= 1) p
where rownum <= 4)
where rnum >= 2
that gives me the following error:
Error SQL: ORA-00918: column ambiguously defined 00918. 00000 - "column ambiguously defined"
If the fields have different names there's no errors. As an example, this query is correct:
select * from
(select rownum rnum, p.* from
(select DEPARTMENTS.DEPARTMENT_ID,
DEPARTMENTS.DEPARTMENT_NAME,
DEPARTMENTS.MANAGER_ID,
EMPLOYEES.EMPLOYEE_ID,
EMPLOYEES.FIRST_NAME,
EMPLOYEES.LAST_NAME,
EMPLOYEES.DETAILS
from HR.EMPLOYEES
INNER JOIN HR.DEPARTMENTS on
HR.DEPARTMENTS.DEPARTMENT_ID=EMPLOYEES.DEPARTMENT_ID
where EMPLOYEES.EMPLOYEE_ID >= 1) p
where rownum <= 4)
where rnum >= 2
What is the correct syntax to make an inner join with pagination, and fields from different tables with the same names? How can I avoid the ORA-00918 error in my first query?
I'm using Oracle 11g.
*; name all columns you're interested in. - Littlefoot