这个存在于存储过程中的查询是做什么的?
What does this query do which exists inside a stored procedure?
我正在尝试理解一个存储过程,并且正在将数据从 Table2 加载到 Table1。表 1 和表 2 中的所有列都相同。
DELETE a FROM Table1 a JOIN (SELECT DISTINCT [Date] FROM Table2) b ON a.Date = b.Date;
您必须使用“存在”命令,例如:
DELETE a FROM Table1 a
where exists (select 0 from Table2 b where a.Date = b.Date);
删除Table1中Table1.Date出现在Table2.Date任意一行的行;即
if Table1 has
Date
2022-01-01
2022-01-02
2022-01-03
and
Table2 has
Date
2022-01-01
2022-01-03
那么如果DELETE语句成功,Table1就只有
Date
2022-01-02
表2不变。
我正在尝试理解一个存储过程,并且正在将数据从 Table2 加载到 Table1。表 1 和表 2 中的所有列都相同。
DELETE a FROM Table1 a JOIN (SELECT DISTINCT [Date] FROM Table2) b ON a.Date = b.Date;
您必须使用“存在”命令,例如:
DELETE a FROM Table1 a
where exists (select 0 from Table2 b where a.Date = b.Date);
删除Table1中Table1.Date出现在Table2.Date任意一行的行;即
if Table1 has
Date
2022-01-01
2022-01-02
2022-01-03
and
Table2 has
Date
2022-01-01
2022-01-03
那么如果DELETE语句成功,Table1就只有
Date
2022-01-02
表2不变。