当前位置: 首页 >数据库 > mysql 去除重复数据 语句

mysql 去除重复数据 语句

纠结的过程:

mysql> select * from role group by role_name,deleted;+---------+-----------+---------+| role_id | role_name | deleted |+---------+-----------+---------+| 2| xue| 12  || 1| zhao  | 12  || 3| zhao  | 13  |+---------+-----------+---------+3 rows in setmysql>  delete from role c where c.role_id not in (select b.role_id from role c group by role_name,deleted);1064 - 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 c.role_id not in (select b.role_id from role c group by role_name,deleted)' at line 1mysql>  select *  from role c where c.role_id not in (select b.role_id from role b  group by role_name,deleted);+---------+-----------+---------+| role_id | role_name | deleted |+---------+-----------+---------+| 4| xue| 12  |+---------+-----------+---------+1 row in setmysql>  delete from role c where c.role_id not in (select b.role_id from role b  group by role_name,deleted);1064 - 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 c.role_id not in (select b.role_id from role b  group by role_name,deleted' at line 1mysql>  delete from role  where role_id not in (select b.role_id from role b  group by role_name,deleted);1093 - You can't specify target table 'role' for update in FROM clausemysql>  delete from role  where role_id not in (select role_id from rolegroup by role_name,deleted);1093 - You can't specify target table 'role' for update in FROM clausemysql>  delete from role  where not role_id  in (select role_id from rolegroup by role_name,deleted);1093 - You can't specify target table 'role' for update in FROM clausemysql>  delete from role  where role_id not in (select t.role_id from role t  group by role_name,deleted);1093 - You can't specify target table 'role' for update in FROM clausemysql>  delete from role  where role_id not in (select t.role_id from role t  group by t.role_name,t.deleted);1093 - You can't specify target table 'role' for update in FROM clausemysql>  delete from role  where role_id NOT IN (select t.role_id from role t  group by role_name,deleted);1093 - You can't specify target table 'role' for update in FROM clausemysql>  delete from role  where role_id NOT IN select *  from ( (select t.role_id from role t  group by role_name,deleted));1064 - 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 'select *  from ( (select t.role_id from role t  group by role_name,deleted))' at line 1mysql>  delete from role  where role_id NOT IN ( select *  from ( (select t.role_id from role t  group by role_name,deleted)));1248 - Every derived table must have its own aliasmysql>  delete from role  where role_id NOT IN ( select *  from  ( select t.role_id from role t  group by t.role_name,t.deleted));1248 - Every derived table must have its own alias

终于通了:

mysql>  delete from role  where role_id NOT IN ( select *  from  ( select t.role_id from role t  group by t.role_name,t.deleted) t1);Query OK, 1 row affected


参考:
mysql比较作呕的一个delete in操作
http://wenda/594988.html

 

作者:amxuefly
来源链接:https://www.cnblogs.com/xfly/p/3881508.html

版权声明:
1、JavaClub(https://www.javaclub.cn)以学习交流为目的,由作者投稿、网友推荐和小编整理收藏优秀的IT技术及相关内容,包括但不限于文字、图片、音频、视频、软件、程序等,其均来自互联网,本站不享有版权,版权归原作者所有。

2、本站提供的内容仅用于个人学习、研究或欣赏,以及其他非商业性或非盈利性用途,但同时应遵守著作权法及其他相关法律的规定,不得侵犯相关权利人及本网站的合法权利。
3、本网站内容原作者如不愿意在本网站刊登内容,请及时通知本站(javaclubcn@163.com),我们将第一时间核实后及时予以删除。





本文链接:https://www.javaclub.cn/database/117634.html

标签:SQL_syntax
分享给朋友:

“mysql 去除重复数据 语句” 的相关文章

MySQL表的增删改查(进阶) 2022年05月16日 21:54:11
会mysql不一定会sql 2022年06月07日 04:41:06
mysql 查询或 2022年06月07日 13:56:22
MYSQL查询一个月前的数据 2022年06月12日 09:48:55
MySQL的查询优化——背后原理 2022年06月14日 22:31:44
mysql简单查询 2022年06月15日 14:03:59
mysql获取上月月份 2022年06月21日 10:38:38