今天,写一条mysql删除语句,我记忆中的语句一直是这样子的:
delete FROM user u where u.userid="1";
可居然报错如下,简直是毁我的常识:
ERROR 1064 (42000): 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 'u where u.userid="1"' at line 1
原来,当from后面的table name加上别名后,delete后面也必须跟上别名,如下才正确:
delete u FROM user u where u.userid="1";
要么都不加别名:
delete FROM user where userid="1";
真是难以置信,我差点以为跟mysql版本有关系!这算是我知识的盲点了,不知大家有中枪的没有?