The join condition for the natural join is basically an EQUIJOIN of all columns with same name. To specify arbitrary conditions or specify columns to join, the ON Clause is used.
- The join condition is separated from other search conditions.
- The ON Clause makes code easy to understand.
- ON Clause can be used to join columns that have different names.
- We use ON clause to specify a join condition. This lets us specify join conditions separate from any search or filter conditions in the WHERE clause.


-
QUERY 1: Write SQL query to find the working location of the employees. Also give their respective employee_id, last_name and department_id?
Input :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); Output :![]()


Input : SELECT l.location_id, l.street_address, l.postal_code, c.country_name FROM locations l JOIN countries c ON (l.country_id = c.country_id); Output :Explanation: The example shown joins the COUNTRY_ID column in the LOCATIONS and COUNTRIES tables using the ON Clause, and thus shows the required details.![]()