如何从选择加入语句中删除结果

发布于 2025-02-13 03:39:54 字数 270 浏览 0 评论 0原文

如何从下面的“选择加入语句”中删除结果。

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'

How do I delete the result from the Select Join statement below.

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'

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

┈┾☆殇 2025-02-20 03:39:54

我猜您想要的是过滤出不需要的结果,您可以在选择查询中使用“不在”,例如过滤掉'id1'和'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')

I guess what you want is filter out the result not needed, you can use "Not in" in your select query, for example filter out 'id1' and 'id2' like following:

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')
ζ澈沫 2025-02-20 03:39:54

据我了解您的问题,您正在问如何从两个表中删除结果集。在SQL语句的上下文中,您不能。 SQL删除语句仅作用于单个表。您必须进行2次删除,首先删除“ Tablea”记录,然后再删除“ TableB”记录。

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

delete from TableB where accountingDate between ...;

As I understand your question, you're asking how to delete the result set from both tables. Within the context of a SQL statement, you can't. A sql delete statement only acts on a single table. You'll have to do 2 deletes, first deleting the 'TableA' record, then the 'TableB' record.

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

delete from TableB where accountingDate between ...;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文