2016-08-03 92 views
1

我正在使用MySql中的一個表「where exists」執行查詢。它在SELECT *下正常工作,但在嘗試執行DELETE而不是SELECT *時失敗。刪除與MySQL中的WHERE EXISTS查詢

如何使用delete執行相同的查詢?提前謝謝了!

select * from MyTable t1 where exists ( 
select * from MyTable t2 where t1.user_id = t2.user_id 
and t1.object_id <> t2.object_id and t2.role = "ADMIN") 
and role = "ORG_MANAGER" 
and object_type = "type_b"; 

回答

1
delete from MyTable t1 
where user_id in (
    select user_id 
    from MyTable t1 
    where exists ( 
    select * from MyTable t2 
    where t1.user_id = t2.user_id 
    and t1.object_id <> t2.object_id 
    and t2.role = "ADMIN") 
    and role = "ORG_MANAGER" 
    and object_type = "type_b"; 
)