This question already has answers here:
Ambiguous column name in SQL Server (3 answers)
Closed 20 days ago.
I am trying to connect to tables with the help of join but it is not working in SQL.
Please guide me to the mistake I am making in this query.
select first_Name, salary, dept
from employees
inner join department on employees.dept = department.dept
I get an error
Ambiguous column name 'dept'
but I don't know why...
I was trying to get the data from both the tables on the bases of dept.
1条答案
按热度按时间1zmg4dgp1#
You select
dept
, but the DBMS want to know whether you meanemployees.dept
ordepartment.dept
, despite them having the same value in your query.It is good practise to qualify all columns with their table name when working with multiple tables:
(Which shows that the join to the department table is completely superfluous as yet.)
As the long table names can make queries harder to read, it is also good practice to use mnemonic table aliases: