Home > database >  The SQL statement
The SQL statement

Time:10-14

A message table (the message) :
Id int id

Review table (comment) :
Id id
User_id user ID
Mess_id message ID

Reply table (reply) :
Id id
Com_id comment ID
User_id user ID

Relationship:
A message table and review table 1: m
Comments on the table and reply table m: n

Q: message table ID is known, use the SQL statement how to realize the table of contents, to remove messages at the same time to delete comments reply table corresponding to the contents of the table and?

Adjure you pass by the bosses to help

CodePudding user response:

 DELETE message, ` comment `, reply 
FROM the message
LEFT the JOIN ` comment ` ON ` comment. ` mess_id=message. Id
LEFT the JOIN reply ON reply.com _id=` comment `. Id
WHERE the message. Id=666
  • Related