这篇文章主要为大家详细介绍了MySQL 数据查重、去重的简单示例,具有一定的参考价值,可以用来参考一下。
感兴趣的小伙伴,下面一起跟随四海网的小玲来看看吧!
有一个表user,字段分别有id、nick_name、password、email、phone。
代码如下:
select * from user where nick_name in (select nick_name from user group by nick_name having count(nick_name)>1);
MySQL 数据查重、去重的实现语句
代码如下:
select * from user where id in (select max(id) from user group by nick_name having count(nick_name)>1);
MySQL 数据查重、去重的实现语句
代码如下:
select * from user where nick_name in (select nick_name from user group by nick_name having count(nick_name)>1) and id not in (select min(id) from user group by nick_name having count(nick_name)>1);
MySQL 数据查重、去重的实现语句
代码如下:
delete from user where nick_name in (select nick_name from (select nick_name from user group by nick_name having count(nick_name)>1) as tmp1) and id not in (select id from (select min(id) from user group by nick_name having count(nick_name)>1) as tmp2);
MySQL 数据查重、去重的实现语句
代码如下:
select * from user where (nick_name,password) in (select nick_name,password from user group by nick_name,password where having count(nick_name)>1);
MySQL 数据查重、去重的实现语句
代码如下:
select * from user where id in (select max(id) from user group by nick_name,password where having count(nick_name)>1);
MySQL 数据查重、去重的实现语句
代码如下:
select * from user where (nick_name,password) in (select nick_name,password from user group by nick_name,password having count(nick_name)>1) and id not in (select min(id) from user group by nick_name,password having count(nick_name)>1);
MySQL 数据查重、去重的实现语句
代码如下:
delete from user where (nick_name,password) in (select nick_name,password from (select nick_name,password from user group by nick_name,password having count(nick_name)>1) as tmp1) and id not in (select id from (select min(id) id from user group by nick_name,password having count(nick_name)>1) as tmp2);
MySQL 数据查重、去重的实现语句
以上就是MySQL 数据查重、去重的实现语句的详细内容,更多关于MySQL 数据查重、去重的资料请关注四海网其它相关文章!
本文来自:http://www.q1010.com/177/19461-0.html
注:关于MySQL 数据查重、去重的简单示例的内容就先介绍到这里,更多相关文章的可以留意四海网的其他信息。
关键词:
四海网收集整理一些常用的php代码,JS代码,数据库mysql等技术文章。