2

I have a USERS table with active and inactive users and I also have another table called Leaders where team leaders are stored (so a list of users).

I want to delete those users in table Leaders that are inactive in table users.

Edit based on comments:

  • Users table: ID and Active
  • Leaders table: ID
Mureinik
  • 297,002
  • 52
  • 306
  • 350

2 Answers2

3

You could use an in condition:

DELETE
FROM   leaders
WHERE  id IN (SELECT id
              FROM   users
              WHERE  active = 0 -- Or however you mark inactive users
             )
Mureinik
  • 297,002
  • 52
  • 306
  • 350
2

You can make joins in delete, similar to select:

delete ld
from leaders ld
join users us on ld.idUser = us.idUser
where us.active = 0
Felipe Martins
  • 184
  • 2
  • 12