Dave Perrett

MySQL Delete on Joined Tables

database, mysql, programming, quickie

If you want to (for example) delete all users with the guest role from your database :

1
2
3
4
5
DELETE FROM user WHERE EXISTS (
    SELECT * FROM role
    WHERE role.id = user.role_id
    AND role.name = 'guest'
);