dongren4147 2014-07-28 18:24
浏览 27
已采纳

从多个MySQL数据库表中删除

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条回答 默认 最新

  • doudengjin8251 2014-07-28 18:26
    关注

    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
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测