1

我想比较两个表 T1 和 T2 并从 T1 中删除其 form_no 小于 form_no 选择表 T2 的记录。我写了以下查询,但它不起作用。

DELETE FROM T1
WHERE --Some Condition--
AND
FORM_NO < (ISNULL((SELECT DISTINCT(FORM_NO) FROM T2 WHERE --Some Condition--), 0))
4

2 回答 2

1

试试这个……希望你能给我们提供完整的查询……

DELETE FROM T1
WHERE --Some Condition--
AND FORM_NO IN (SELECT DISTINCT(t.FORM_NO) FROM T1 AS t
        LEFT JOIN T2 AS s
        ON -- COMMON COLUMN
        WHERE t.FORM_NO < s.FORM_NO)
于 2012-12-07T06:45:02.300 回答
0

如果您有一个公共字段并想删除此字段的加入:

delete from t11 
    from t1 t11
        join t2 on (t11.commonID=t2.commonID)
    where (t11.FORM_NO<t2.FORM_NO)

如果您想要的正是您所要求的:

delete from t1 where FORM_NO<(select min(FORM_NO) from t2) 
于 2012-12-07T07:12:43.857 回答