0

Why is it when I delete data from multiple tables in MySQL nothing happens? My scenario is when I delete a school from university all the courses, faculty and students enrolled in that school is also deleted.

Here's how I do it

DELETE FROM university, courses, faculty, students 
INNER JOIN university 
INNER JOIN courses 
INNER JOIN faculty 
INNER JOIN students ON university.id = courses.university_id
AND  courses.id = faculty.courses_id
AND faculty.id = students.faculty_id 
WHERE university.id = :id

WHERE :id = id from PHP code.

Reference: Mysql - delete from multiple tables with one query and http://www.mysqltutorial.org/mysql-delete-statement.aspx

1
  • Why are you mixing join styles? Commented Jul 28, 2014 at 18:26

1 Answer 1

2

This is the syntax to use

DELETE university, courses, faculty, students 
FROM university 
INNER JOIN courses ON university.id = courses.university_id
INNER JOIN faculty ON courses.id = faculty.courses_id
INNER JOIN students ON faculty.id = students.faculty_id 
WHERE university.id = :id
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.