开发者社区> 问答> 正文

Mysql删除两张表的关联数据问题? 400 报错

Mysql删除两张表的关联数据问题? 400 报错 Mysql语句:delete intd,reply from intd as t1 left join reply as t2 on t1.id=t2.reid where intd.id='31'  

其中的intd,reply是表名,id和reid是对应表内的字段。我想删除两张表的所有内容,它们的联系是intd表的id字段等于reply表的reid字段,怎么样通过确定intd表的id字段删除对应的全部内容?谢谢


我在phpMyAdmin测试,其中的intd,reply标红出错。

执行提示出错:
静态分析:


分析时发现3个错误。


Unexpected token. (near "intd" at position 7)
Unexpected token. (near "," at position 11)
Unexpected token. (near "reply" at position 12)
SQL 查询:


delete intd,reply from intd as t1 left join reply as t2 on t1.id=t2.reid where intd.id='31'


MySQL 返回: 文档


#1109 - Unknown table 'intd' in MULTI DELETE


展开
收起
爱吃鱼的程序员 2020-06-02 17:37:34 456 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

    如果你是利用字段来进行多表联合删除的话,应该这么写

    DELETE intd,reply FROM intd,reply WHERE intd.id=reply.reid AND intd.id= '31'



    如果你是要 删除两张表的所有内容,那么

    delete from 表名 或者 truncate table 表名;

    ######感谢回复,是要多表联合删除######DELETE FROM table 呀?为何你的语法这么奇怪的

    delete from intd as t1 left join reply as t2 on t1.id=t2.reid where intd.id=31



    ######感谢回复######delete  from intd   where id='31'  ;
    delete  from reply where reid ='31'  ;
    ######感谢回复。###### delete t1,t2 from intd as t1 left join reply as t2 on t1.id=t2.reid where intd.id='31'######回复 @songoex : delete t1,t2 from intd t1 join reply t2 on t1.id=t2.reid and t1.id='31'######感谢回复。不过不知道是不是我的Mysql版本问题,不能够执行。http://dev.mysql.com/doc/refman/5.7/en/delete.html
    2020-06-02 17:37:50
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
搭建电商项目架构连接MySQL 立即下载
搭建4层电商项目架构,实战连接MySQL 立即下载
PolarDB MySQL引擎重磅功能及产品能力盛大发布 立即下载

相关镜像