查找没有重复的部门名称和位置

时间:2019-01-31 11:26:51

标签: mysql sql

SELECT D.dname, L.dlocation
FROM DEPARTMENT D, dept_locations L

输出:

dname   dlocation
Research    Houston
Research    Stafford
Research    Bellaire
Research    Houston
Research    Sugarland
Administration  Houston
Administration  Stafford
Administration  Bellaire
Administration  Houston
Administration  Sugarland
Headquarters    Houston
Headquarters    Stafford
Headquarters    Bellaire
Headquarters    Houston
Headquarters    Sugarland

期望的复活:

dname   dlocation
Headquarters    Houston
Administration  Stafford
Research    Bellaire
Research    Houston
Research    Sugarland

1 个答案:

答案 0 :(得分:0)

您需要内部联接

SELECT D.dname, L.dlocation
FROM DEPARTMENT D inner join dept_locations L
on d.departmentid=l.departmentid