简体   繁体   English

从一个表中删除基于其他两个表列?

[英]Delete from one table based off two other tables column?

I have 3 tables: t1,t2,t3 我有3张桌子:t1,t2,t3

t1 has one column: AccountID t1有一列:AccountID

t2 columns: AccountID, Remaining, StatusID, DueDate t2列:AccountID,剩余,StatusID,DueDate

t3 columns: AccountID, Remaining, StatusID, DueDate t3列:AccountID,剩余,StatusID,DueDate

Here is my issue: 这是我的问题:

I need to delete all the rows in t1 table only if t2.Remaining = 0 AND t3.Remaining = 0 仅在t2.Remaining = 0 AND t3.Remaining = 0时,才需要删除t1表中的所有行。

Can anybody help a brother out? 有人可以帮兄弟吗? I would greatly appreciate it, and will follow the best answer with an upvote/retweet your status/like your facebook page/give you money. 我将不胜感激,并会以最好的答案支持/转发/转发您的状态/喜欢您的Facebook页面/为您赚钱。 HAHA j/k bout the money though. 哈哈j / k虽然钱。

Delete all rows from t1 for which there is a row in t2 and t3 where remaining equals 0. If there is a foreign key constraint, it is assumed it is cascading, so that all corresponding rows in t2 and t3 will automatically be deleted as well. 从t1删除所有在t2和t3中剩余一行等于0的行。如果存在外键约束,则假定它是级联的,因此t2和t3中的所有对应行也将被自动删除。 。

DELETE FROM t1
WHERE EXISTS
    (SELECT * FROM t2 WHERE t1.AccountId = AccountID AND Remaining = 0)
AND EXISTS
    (SELECT * FROM t3 WHERE t1.AccountId = AccountID AND Remaining = 0);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 根据另外两个表从一个表中选择值(关系) - Select values from one table based on two other tables (relational) 根据其他两个表中的数据更新一个表 - Update one table based on data from two other tables 从一个表中进行选择,然后根据条件插入到另外两个表中 - SELECT from one table, INSERT into two other tables based on condition 将一个表中的一列与其他两个表中的另一列合并 - combine one column from one table with other column from two other tables sql 从两个表中删除两列重复项,每个表中的一列 - Delete two-column duplicates from two tables, one column on each table 从两个联接的表中选择,其中表的一列由另一列中的两个引用 - Selecting from two joined tables where one column of a table is referred by two from the other one 更新基于来自两个匹配表的记录的列? - Updating a column based off records from two tables matching? 如何基于两个表中的多个值删除一个表中的值 - How to delete values of one table based on multiple values from two tables 根据一张表中的纬度和经度是否存在于另一张表的多边形中来连接两张表(来自不同的数据库) - Joining two tables (from different databases) based on whether lat and long from one table are present in the polygon of the other 根据两个表选择记录,其中一个表中的一列使用SQL从另一个表列的记录开始 - Select records based on two tables where one column in one table starts with the records from another tables column using SQL
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM