我有一个删除查询
delete from Admin_course_groups ac join admin_course_details ad
on ac.fk_c_id=ad.fk_c_id
where fk_g_id=1 and type='G'
当我运行此查询时,出现错误
MySQL said: Documentation
1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use
near 'ac inner join admin_course_details ad on ac.fk_c_id=ad.fk_c_id' at line 1
我的 table Admin_course_groups
a_id | fk_c_id|fk_g_id|type
1 1 1 G
2 3 1 G
admin_course_details
d_id | status | fk_c_id |fk_user_id
1 1 1 2
2 1 3 2
任何帮助将不胜感激。
最佳答案
您需要指定删除的目标表,并且您应该在此处使用别名:
DELETE acg -- or acg, acd if you wanted to target both tables
FROM Admin_course_groups acg
INNER JOIN admin_course_details acd
ON acg.fk_c_id = acd.fk_c_id
WHERE
fk_g_id = 1 AND type = 'G';
关于Mysql join 删除查询问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52847558/