删除MySQL中的JOIN下面是创建我的表的脚本:CREATE TABLE clients (
client_i INT(11),
PRIMARY KEY (client_id));CREATE TABLE projects (
project_id INT(11) UNSIGNED,
client_id INT(11) UNSIGNED,
PRIMARY KEY (project_id));CREATE TABLE posts (
post_id INT(11) UNSIGNED,
project_id INT(11) UNSIGNED,
PRIMARY KEY (post_id));在我的PHP代码中,当删除客户端时,我希望删除所有的项目帖子:DELETE FROM postsINNER JOIN projects ON projects.project_id = posts.project_idWHERE projects.client_id = :client_id;POST表没有外键。client_id,只有project_id..我想删除已通过的项目中的帖子。client_id.这是不可行的,因为没有删除的帖子。
3 回答
宝慕林4294392
TA贡献2021条经验 获得超8个赞
posts
DELETE postsFROM postsINNER JOIN projects ON projects.project_id = posts.project_idWHERE projects.client_id = :client_id
沧海一幻觉
TA贡献1824条经验 获得超5个赞
DELETE posts FROM postsINNER JOIN projects ON projects.project_id = posts.project_idWHERE projects.client_id = :client_id
table_name1
table_name2
DELETE projects FROM posts INNER JOIN [...]
DELETE posts, projects FROM posts INNER JOIN [...]
order by
limit
DELETE p FROM posts as p INNER JOIN [...]
富国沪深
TA贡献1790条经验 获得超9个赞
DELETE FROM posts USING posts, projects WHERE projects.project_id = posts.project_id AND projects.client_id = :client_id;
添加回答
举报
0/150
提交
取消