Join with the ON clause

•Specify column to join
•Can also join columns that have different names

Select e.employee_id, e.last_name, e.department_id, d.department_id, d.location_id
From employees e join departments d
On (e.department_id = d.department_id);



Wherever a department_id in the EMPLOYEES table equal a department_id in the DEPARTMENTS table, result returned.



3-way joins with ON


Select employee_id, city, department_name
From employees e
Join departments d
On d.department_id = e.department_id
Join locations l
On d.location_id = l.location_id;








0 comments:

Post a Comment