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?

25th Aug 2016, 5:36 PM
Smit Shah
Smit Shah - avatar
5 Réponses
+ 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;
25th Aug 2016, 6:08 PM
Tiger
Tiger - avatar
0
select * from user left join detail on user.id = detail.user_id left join status on detail.status_id = status.status_id
2nd Nov 2016, 12:40 PM
robin cruz
robin cruz - avatar
- 3
delete*from user,detail,status where Id=7;
6th Sep 2016, 2:32 PM
Essien Samuel
Essien Samuel - avatar
- 6
lol
25th Aug 2016, 5:42 PM
kubikovce
kubikovce - avatar
- 6
v
26th Aug 2016, 7:52 AM
sombra