Code24Lab

ANSI Joins in Oracle: JOIN … ON, USING and Lost Rows

Lesson 1 of 22Lab

All lessons

You are not signed in — the lab works, but your progress is not saved. Sign up

Lesson 1 of 22 is free. Unlock all 22 hands-on labs, the final exam and your certificate.

Buy course — CHF 19.90
Read first

The SQL

SELECT d.dept_id, d.dept_name,
       SUM(e.salary)        AS payroll,
       ROUND(AVG(e.salary)) AS avg_salary
FROM   employees e
JOIN   departments d
  ON   d.dept_id = e.dept_id
GROUP  BY d.dept_id, d.dept_name
ORDER  BY d.dept_id;
Prefix every column with its table alias (e.salary, d.dept_name). In a join, an unprefixed column that exists in both tables raises ORA-00918: column ambiguously defined.
Loading the lab…