0
How to query values from 3 tables at once
I have 3 tables (user,detail,status) User - id - email Detail - id - user_id (foreign key,User table) - age - status_id(unique_key) Status - id - status_id (foreign_key,Detail table) - text Now how can I delete a user, i need to delete all of his records from all the three tables, how can i achive this with a single query! Is there any other way then setting Cascade and then deleting the primary key?
5 Answers
+ 9
you could first set cascade delete set for all relations beween tables.
Then you could only delete the user from user table and all records of detail and status tables related to the user will automatically deleted.
single query ex:
DELETE * FROM user WHERE id=5;
0
select * from user left join detail on user.id = detail.user_id left join status on detail.status_id = status.status_id
- 3
delete*from user,detail,status where Id=7;
- 6
lol
- 6
v