[英]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.