[SQL]刪除兩筆表單內部包含的資料

表單A,ID
A
B
C
D

表單B,ID
B
C

交叉查詢後只會有BC重複,但想刪除不重複的部分AD
 


 

DELETE FROM ReportDetail where ReportDetail.UserID in (
SELECT DISTINCT ReportDetail.UserID FROM ReportDetail where ReportDetail.UserID  not in (
SELECT Users.UserID FROM Users))
DELETE FROM ReportDetail where ReportDetail.UserID in (
刪除報表ID內包含
SELECT DISTINCT ReportDetail.UserID FROM ReportDetail where ReportDetail.UserID not in (
報表ID不包含
SELECT Users.UserID FROM Users))
使用者ID

的多筆資料