以下是我的表格:
SELECT employees.id, employees.name, empolyees.dept_id, departments.id,
departments.name
FROM employees, departments
WHERE employees.dept_id = departments.dept_id
ORDER BY employees.name;
我加入这两张桌子了吗?
答案 0 :(得分:0)
更好地使用显式连接语法
SELECT e.id, e.name, e.dept_id, d.id, d.name
FROM empolyees e
INNER JOIN departments d ON e.dept_id = d.id
ORDER BY e.name
你使用了不存在的departments.dept_id
。它是departments.id
答案 1 :(得分:0)
可以说:
SELECT e.id, e.name, empolyees.dept_id, d.id, d.name
FROM employees e
inner join departments d on e.dept_id = d.dept_id
ORDER BY e.name;