mysql-去除重复数据并且添加

来源:互联网 发布:拜占庭是罗马 知乎 编辑:程序博客网 时间:2024/06/07 22:18


1.创建一个和B表一个的A表

2.添加B表中所有不重复的数据到A表

3.查询B,和 A 表进行判断 数据是否正确

4.删除B表改名A表为B表


distinct:

在使用MySQL时,有时需要查询出某个字段不重复的记录,这时可以使用mysql提供的distinct这个关键字来过滤重复的记录,但是实际中我们往往用distinct来返回不重复字段的条数(count(distinct id)),其原因是distinct只能返回他的目标字段,而无法返回其他字段,例如有如下表user:


create table tmp like t_yuesao_poster;insert into tmp select id,openid,image,max(time) as time from t_yuesao_poster group by openidselect distinct * from  t_yuesao_poster where t_yuesao_poster.openid not in (select openid from t_user_info)


原创粉丝点击