关于MySQL的DELETE语句给表加别名执行会报错
错误信息
MySQL Error: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 't1 where t1.SYS_ID = 'fjgl'' at line 1
使用的MySQL版本
5.7.18
解决方案
因为在这个版本中delete语法有所特殊
第一种:
delete 表别名 from 表名 表别名 where 别名.字段 = ‘zjh’;
例如:
delete tb from userInfo tb where tb.id_card = ‘111232131’;
第二种:
去掉别名 如: delete from 表名 where 字段 = ‘zjh’;
例如:
delete from userInfo where id_card = ‘111232131’;
个人总结
经过我个人测试上述问题,在MySQL 8.0.17中并没有这个问题,所以这个问题,在后续的版本升级中已经解决。具体哪个版本开始没有这个问题的,没有去查证,还请谅解。