我正在尝试删除SQL查询中的重复项,并且我一直在重复 继承了我到目前为止的代码
SELECT e1.LName, w1.PNo, e2.LName, w2.PNo, p.Plocation
FROM Employee e1, Employee e2, Works_On w1, Works_On w2, Project p
WHERE e1.SSN = w1.ESSN AND
e2.SSN = w2.ESSN AND
e1.SSN != e2.SSN AND
w1.PNo = w2.PNo AND
w1.Pno = p.PNumber AND
p.PLocation = 'Houston'
ORDER BY e1.LName
这是输出
LNAME PNO LNAME PNO PLOCATION
Borg 20 Wong 20 Houston
Borg 20 Wallace 20 Houston
Narayan 3 Wong 3 Houston
Wallace 20 Wong 20 Houston
Wallace 20 Borg 20 Houston
Wong 20 Borg 20 Houston
Wong 3 Narayan 3 Houston
Wong 20 Wallace 20 Houston
正如您所看到的,某些行具有重复项,其中翻转了姓氏。我不确定我应该删除那些行
编辑: 而不是把e1.SSN!= e2.SSN,我改为e1.SSN> e2.SSN得到了我想要的结果 我现在得到这个结果
LNAME PNO LNAME PNO PLOCATION
Borg 20 Wallace 20 Houston
Wong 20 Wallace 20 Houston
Wong 3 Narayan 3 Houston
Wong 20 Borg 20 Houston