使用mysql执行删除语句时出现的问题

来源:互联网 发布:软件项目管理常见问题 编辑:程序博客网 时间:2024/05/29 16:13

mysql执行删除sql时

1、不能有别名,例如:delete from user t where t.user_id=’?’
user表后面不能有那个t
否则报错:
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 ‘t where t.user_id=’?” at line 1

2、where条件如果有子查询,并且是查询当前表的,需要用括号包起来当做临时表,再查一次
例如:where user_id in (select user_id from user)会执行失败,应改成
where user_id in (select user_id from (select user_id from user) as t2)
注意:当用括号包起来作为临时表时,一定要起个名字,像上面我起的名字就是t2
否则报错:
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 ‘where user_id in (select user_id from user ) at line 1