如何从select联接语句中删除结果



如何从下面的SelectJoin语句中删除结果。

SELECT 
t2.TransactionID
FROM
TableA AS t1
INNER JOIN 
TABLEB AS t2 ON t1.TransactionID = t2.TransactionID
WHERE
t2.accountingDate BETWEEN '2010-01-01 00:00:00.0000000' AND '2011-12-30 00:00:00.0000000'

我想你想要的是过滤掉不需要的结果,你可以使用"不在";例如,在您的选择查询中,过滤掉"id1"one_answers"id2",如下所示:

Select t2.TransaationID from TableA as t1 INNER JOION TABLEB as t2 ON t1.TransactionID = t2.TransactionID where t2.accountingDate BETWEEN '2010-01-01 00:00:00.0000000' and ''2011-12-30 00:00:00.0000000 
and t1.TransactionID not in ('id1','id2')

据我所知,您正在询问如何从两个表中删除结果集。在SQL语句的上下文中,您不能。sql delete语句只作用于单个表。您必须进行两次删除,首先删除"TableA"记录,然后删除"TableB"记录。

delete from tableA where transctionID in
(select transactionID from tableB where accountingDate between ...);
delete from TableB where accountingDate between ...;

相关内容

  • 没有找到相关文章

最新更新