1

我正在尝试从另一个表中不存在的表中删除列表。我可以选择列表:

SELECT count(mlsnum) as oldRecords
FROM coordinates
WHERE mlsnum NOT IN
(SELECT mlsnum 
 FROM RETS_Listings_full)

但是当我尝试删除列表时,我无法

delete FROM coordinates t1
LEFT JOIN RETS_Listings_full t2 
ON t2.MLSNUM = t1.MLSNUM
WHERE t2.mlsnum IS NULL

错误显示 - Msg 102, Level 15, State 1, Line 1 “t1”附近的语法不正确。

4

4 回答 4

2

...where they do not exist...

You are quite near to the solution: use NOT EXISTS:

DELETE FROM coordinates t1
WHERE NOT EXISTS
(
    SELECT 1 FROM RETS_Listings_full t2 
    WHERE t1.mlsnum = t2.mlsnum 
)
于 2013-04-24T15:38:59.493 回答
1

您可以通过这种方式检索mlsnum并删除列表

DELETE FROM coordinates
WHERE mlsnum IN (
  SELECT mlsnum
  FROM coordinates
  WHERE mlsnum NOT IN (
   SELECT mlsnum
   FROM RETS_Listings_full)
  )
于 2013-04-24T15:38:04.763 回答
1
delete from mytable where somecommonid not in(select id from myothertable) 
于 2013-04-24T15:38:45.667 回答
0

第二个查询的正确语法

DELETE t1
FROM coordinates t1 LEFT JOIN RETS_Listings_full t2 ON t2.MLSNUM = t1.MLSNUM
WHERE t2.mlsnum IS NULL
于 2013-04-24T16:24:01.490 回答