Reputation: 2823
I've got three tables:
department
, employee
and telephone
employee
has columns EmpNo
, Surname
, Firstname
and DeptNo
.
telephone
has columns EmpNo
and Extension
.
department
has columns DeptNo
and DeptName
.
What I am trying to get is the full name, department name and telephone extension.
I think I am almost there but its not working yet.
My query
SELECT e.Firstname, e.Surname, d.DeptName, t.Extension
FROM employee AS e
INNER JOIN department AS d
INNER JOIN telephone AS t
ON e.DeptNo = d.DeptNo
ON t.EmpNo = e.EmpNo;
Upvotes: 0
Views: 48
Reputation: 5271
To fix your problem, move one of the ON
clauses before the next JOIN
SELECT e.Firstname, e.Surname, d.DeptName, t.Extension
FROM employee AS e
INNER JOIN department AS d
ON e.DeptNo = d.DeptNo
INNER JOIN telephone AS t
ON t.EmpNo = e.EmpNo;
Upvotes: 7
Reputation: 793
The ON clause must follow the JOIN that it is modifying.
So:
INNER JOIN department d ON e.DeptNo = d.DeptNo
and
INNER JOIN telephone t ON t.EmpNo = e.EmpNo;
Upvotes: 2
Reputation: 3591
Your query is wrong. Join is not in correct format. Use like below
SELECT e.Firstname, e.Surname, d.DeptName, t.Extension
FROM employee AS e
inner join department AS d
ON e.DeptNo = d.DeptNo
inner join telephone AS t
ON t.EmpNo = e.EmpNo;
Upvotes: 1