求教下列sql语句
delete users as a from users as a,(
select min(id) , name from users group by name having count(name) > 1
) as b
where a.name = b.name and a.id <> b.id;
为什么delete后面要加users as a,如果不加就出错呢?
------解决方案--------------------MYSQL语法 要求
Multiple-table syntax:
DELETE [LOW_PRIORITY] [QUICK] [IGNORE]
tbl_name[.*] [, tbl_name[.*]] ...
FROM table_references
[WHERE where_condition]
------解决方案--------------------
不加强users as a
那变成
delete from users as a,(
select min(id) , name from users group by name having count(name) > 1
) as b
则MYSQL从哪张表删除记录吗? 显然MYSQL会试图从两张表同时删除记录,而你的B表显示不是一个可以删除记录的表。