2

I am executing the query with "where exists" using one table in MySql. It works fine with SELECT *, but fails when I try to do DELETE instead of SELECT *.

How to perform the same query with delete? Many thanks in advance!

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";
yinjia
  • 804
  • 2
  • 10
  • 20

1 Answers1

2
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";
)
wogsland
  • 9,106
  • 19
  • 57
  • 93
Sean Han
  • 36
  • 2