我对旧的JOIN语句并寻求一点友好的帮助不太满意。我有两个表,可以说表Employee
:
LastName DepartmentID
Rafferty 31
Jones 33
Steinberg 33
Robinson 34
Smith 34
John NULL
和表
Department
:DepartmentID DepartmentName
31 Sales
33 Engineering
34 Clerical
35 Marketing
如果我想返回
DepartmentID=31
的结果,而仅返回Employee.DepartmentID = Department.DepartmentID
的结果,那么返回的结果将如下所示:Employee.LastName Employee.DepartmentID Department.DepartmentName
Rafferty 31 Sales
(我们可以删除DepartmentID之一,因为它们相同)-完成该任务的SQL语句是什么?
谢谢
最佳答案
SELECT e.LastName, e.DepartmentID, d.DepartmentName
FROM Employee e
INNER JOIN Department d ON d.DepartmentID = e.DepartmentID
WHERE d.DepartmentID = 31
关于mysql - MySQL JOIN语句交叉联接?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/8187709/