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

Community
  • 1
  • 1
LoLcattt
  • 3
  • 2

1 Answers1

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
juergen d
  • 201,996
  • 37
  • 293
  • 362