Question : ORA-00904

Hi When I user joining condition

 WHERE p1.emp_id = p.emp_id

I am getting error

ORA-00904: "P"."emp_ID": invalid identifier

How can I write the resolve the error
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
SELECT
*
  FROM 
       (SELECT   emp_id,
                 MAX (CASE  WHEN visit_number = (SELECT  visit_number
                               FROM  (SELECT  visit_number, rownum srl
                                        FROM  (SELECT  visit_number
                                                 FROM  emps p1,
                                                       depts s,
                                                       edu_emp_visit_types_xref x
                                                 WHERE p1.emp_id = p.emp_id
                                                 AND   p1.dept_id = s.dept_id
                                                 AND   x.edu_id = 1
                                                 AND   x.country = s.country
                                                 AND   x.emp_visit_type_name = 'Enrolled'
                                                 ORDER BY visit_order))
                               WHERE  srl = 1)  THEN visit_date END  ) visit1
               FROM emp_VISITS
           WHERE edu_id = 1
        GROUP BY emp_id) tl,
        empS p,
        deptS s
 WHERE p.emp_id = edc.emp_id
   AND p.emp_id = tl.emp_id
   AND s.dept_id = p.dept_id
Open in New Window Select All

Answer : ORA-00904

Error is due to the inner most sub query:-
SELECT visit_number FROM emps p1, depts s, edu_emp_visit_types_xref x
WHERE p1.emp_id = p.emp_id
AND p1.dept_id = s.dept_id
AND x.edu_id = 1
AND x.country = s.country
AND x.emp_visit_type_name = 'Enrolled'
ORDER BY visit_order

there is no table alias named P in from clause thats why p.emp_id is invalid
Random Solutions  
 
programming4us programming4us