如何使用subselect或LEFT join执行此DELETE查询

时间:2015-06-05 12:19:19

标签: mysql join

我正在尝试删除任务从我的任务表WHERE,任务ID是例如100,并且删除用户创建的任务WHERE或他的团队的成员在用户表中分配了较小的user_role

我想知道这样的事情是否会产生魔力或者达到这个目的的正确方法是什么?

DELETE FROM tasks t LEFT JOIN users u ON u.user_id = 1 WHERE task_id = 677 
AND createdby 
IN((SELECT u1.user_id FROM users u1 WHERE u1.user_team = u.user_team 
AND taskrspnsble 
IN((SELECT u2.user_id FROM users u2 WHERE u2.user_role <= u.user_role))
))

1 个答案:

答案 0 :(得分:0)

我认为我的逻辑解释清楚了吗?我只是想通了。这是正确的答案!

 DELETE FROM tasks 

WHERE task_id = 1 
AND createdby IN(
                (SELECT u1.user_id FROM users u1 WHERE u1.user_team 
                 IN
                 (SELECT u2.user_team FROM users u2 WHERE u2.user_role <= (SELECT u3.user_id FROM users u3 WHERE u3.user_id = 1)
                )
                ))