sql筛选出重复数据的方法:使用“select * from 表名 where 条件”语句来筛选重复数据;可以使用一个或者多个表,表之间使用逗号(,)分割,并使用WHERE语句来设定查询条件。
/2021/04/25383f2b.jpg
本教程操作环境:windows7系统、mysql8版本、Dell G3电脑。
在电脑上打开数据库,这里新建一张含有重复数据的user表做示例。
class="ikqb_img" /2021/04/93cebaac.jpg" style="border: 0px;max-width: 500px;max-height: 340px;vertical-align: bottom;border-radius: 6px;cursor: auto
查询出了数据库中user表的重复数据。
select * from user where name in (select name from user group by name having count(name) > 1)
class="ikqb_img" /2021/04/9492dd24.jpg" style="border: 0px;max-width: 500px;max-height: 340px;vertical-align: bottom;border-radius: 6px;cursor: auto
删除姓名重复的数据
delete from user where name in (select name from user group by name having count(name) > 1)
class="ikqb_img" /2021/04/3312f1e5.jpg" style="border: 0px;max-width: 500px;max-height: 340px;vertical-align: bottom;border-radius: 6px;cursor: auto
去掉重复数据,这里去掉了张三的重复数据
select distinct name from user
class="ikqb_img" /2021/04/7bdb2b2d.jpg" style="border: 0px;max-width: 500px;max-height: 340px;vertical-align: bottom;border-radius: 6px
去掉班级相同的重复数据
select distinct class from user
class="ikqb_img" /2021/04/73acaafe.jpg" style="border: 0px;max-width: 500px;max-height: 340px;vertical-align: bottom;border-radius: 6px
去掉两个字段的重复数据
select distinct name,class from user
class="ikqb_img" /2021/04/93c3ea41.jpg" style="border: 0px;max-width: 500px;max-height: 340px;vertical-align: bottom;border-radius: 6px;cursor: zoom-in
相关免费学习推荐:mysql视频教程
以上就是sql如何筛选出重复数据的详细内容,更多请关注北冥有鱼其它相关文章!
本文转载自【PHP中文网】,希望能给您带来帮助,苟日新、日日新、又日新,生命不息,学习不止。