0

I'm trying to use the following SELECT statement to craft a DELETE statement after I get it working.

Basically table "listing" has a bunch of record that need to be removed. If the EmpNo cannot be found in address table then I want to remove the record from listing table. I keep getting a invalid syntax. What am I doing wrong?

SELECT A.*
FROM address A
LEFT JOIN listing B
USING (EmpNo)
WHERE B.EmpNo IS <> A.EmpNo
4

1 回答 1

2

在此处删除IS关键字:

WHERE B.EmpNo IS <> A.EmpNo

应该:

WHERE B.EmpNo  <> A.EmpNo

如果EmpNo在两个表中都存在同名,USING则将在那里正常工作。否则,您可以更明确一点ON

FROM 
  address A
  LEFT JOIN listing B
    ON A.EmpNo = B.EmpNo

要在 中查找A不匹配的记录B,请测试B.EmpNo IS NULL而不是B.EmpNo <> A.EmpNo

WHERE B.EmpNo IS NULL
于 2013-02-26T20:13:17.757 回答