Your joins are inner joins, so only when data is in all three tables will you have a result to delete (the result set of your joins).
Assuming you want to do the following:
- Delete the a role
roles.ROLEID = <some_role_id>
- Delete all
user_role records with user_role.ROLEID = <some_role_id>
- Delete all
role_perm records with user_role.ROLEID = <some_role_id>
Convert them to left outer joins, with the first table the main table all others depend on.
DELETE t1, t2, t3
FROM roles as t1
LEFT JOIN user_role as t2 on t1.ROLEID = t2.ROLEID
LEFT JOIN role_perm as t3 on t1.ROLEID = t3.ROLEID
WHERE t1.ROLEID = $role_id
The above will work without the cascade foreign key constraint. If you've the cascade and assuming it's on Foreign keys tied to roles.ROLEID you'll only need DELETE t1 FROM... as the delete will cascade to all other tables.
Thus if both user_role and role_perm have cascading FK's on roles.ROLEID:
DELETE FROM roles WHERE t1.ROLEID = $role_id;
Now, I run like the plague from cascading FK's and prefer the explicit delete of the first query. Have had too many unexpected cascading deletes in my life I guess.