Home  >  Article  >  Backend Development  >  mysql查询多条数据的有关问题

mysql查询多条数据的有关问题

WBOY
WBOYOriginal
2016-06-13 10:17:00818browse

mysql查询多条数据的问题
select多条数据 如何查出来里面的重复的 并且提示出来哪几天 最后把不重复的插入数据库中

------解决方案--------------------
如果你是想清除表里面的重复记录的话,可以使用INSERT INTO ..... SELECT .....语句完成。
建立一个与原表的结构完全相同的表,通过上面的语句把原表的记录全部插入到新建的表中。新建的表,需要建立一个唯一型复合索引,这样的话在插入的时候,遇到相同的记录就会自动跳过而不会插入。
唯一型复合索引的SQL语句类似:

SQL code
ALTER TABLE  `mytable` ADD UNIQUE (`username` ,`age`);<div class="clear">
                 
              
              
        
            </div>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn