Mysql join 删除查询问题

标签 mysql

我有一个删除查询

     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/

相关文章:

php - 在 Kendo UI 中显示编码的 HTML

mysql - 确保在 MySQL 中填写顺序字段

mysql - 比较 ActiveRecord 结果并只使用不同的结果

mysql - 如何为新的 RDS MySQL 实例初始化字符集设置

mysql - 如何在 CI Bonfire 中使用 MySql 查询

php - Joomla 3 : manually updating a table in the database

mysql 比较特定日期

.net - 从 DataGrid 获取特定值

mysql - 创建临时表后缺少 'end'错误

MySQL group_concat with select inside select