sql-server – Sql server DELETE和WITH子句
发布时间:2020-05-24 14:35:05 所属栏目:MsSql 来源:互联网
导读:我需要构建一个SQL语句来从某个表中删除与另一个select语句匹配的记录. 在Teradata我们使用 delete from table1 where (col1, col2) in ( select col1,col2 from table2) 在SQL Server中,不允许在WHERE..IN子句中包含多于一列的列.我以为我可以使用WITH子句:
|
我需要构建一个SQL语句来从某个表中删除与另一个select语句匹配的记录. 在Teradata我们使用 delete from table1 where (col1,col2) in ( select col1,col2 from table2 ) 在SQL Server中,不允许在WHERE..IN子句中包含多于一列的列.我以为我可以使用WITH子句: with tempTable(col1,col2) as ( select col1,col2 from table2 ) delete from table1 where table1.col1 = tempTable.col1 and table1.col2 = tempTable.col2 如何使用WITH..DELETE子句?还有另一种方式吗? 解决方法这应该这样做:DELETE Table1
from Table1 t1
inner join tempTable t2
on t2.Col1 = t1.Col1
and t2.Col2 = t1.Col2 (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
推荐文章
站长推荐
热点阅读
