Delete join from two tables

隐身守侯 提交于 2019-12-25 08:08:36

问题


I need to create a join that will delete the entries in two tables. The delete will happen in projects when the project_id in the table is equal to the one on the page of the php document. I need the link entries on project_course to also be deleted. This is the code I have currently.

$deleteSQL = sprintf("DELETE FROM projects p
INNER JOIN project_course pc
WHERE p.Project_id=%s",
                   GetSQLValueString($_GET['Project_id'], "int"));

Anybody know how to do this? I haven't done a join to delete before, just a normal join.


回答1:


You dont have to explicitly do this with joined queries.You can use DELETE CASCADE in table definition. Refer How do I use on delete cascade in mysql?



来源:https://stackoverflow.com/questions/10768372/delete-join-from-two-tables

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!