我对旧的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语句是什么?
由于
答案 0 :(得分:1)
SELECT e.LastName, e.DepartmentID, d.DepartmentName
FROM Employee e
INNER JOIN Department d ON d.DepartmentID = e.DepartmentID
WHERE d.DepartmentID = 31
答案 1 :(得分:0)
有隐喻的鱼:
SELECT * FROM员工INNER JOIN部门在employee.departmentId = department.departmentId WHERE departmentId = 31
这是隐喻性的钓鱼课程:
答案 2 :(得分:0)
SELECT e.LastName, e.DeparmentID, d.DepartmentName
FROM employee AS e INNER JOIN department AS d ON e.DepartmentID = e.DepartmentID
WHERE e.DepartmentID = 31
我们将使用INNER JOIN
使用ON
部分匹配每个表中的记录 - >等同于两个表之间的离开值。