简体   繁体   中英

Delete join from two tables

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.

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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM