![]() |
|
|||||||
|
|
Thread Tools | Display Modes |
|
#1
IP: 153.99.38.51
|
|||
|
|||
|
Mysql delete duplicate records leaving one row. Consider that there are many duplicate records in the table and you want to remove it. Now, we can select it by applying GROUP BY but the question is how to delete all the duplicate records (of field some_id below) EXCEPT one that should be there. So, lets say I have following table with duplicate data as shown:
Tablename: test unique_id | some_id -------------------- 1 | 1 2 | 1 3 | 2 4 | 2 5 | 1 Solution: DELETE t1 FROM test t1, test t2 WHERE t1.unique_id > t2.unique_id AND t1.some_id = t2.some_id; Final Result: unique_id | some_id -------------------- 1 | 1 3 | 2 |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Flag large number random records in a MySQL database - one time only | Galax city | MySQL | 1 | 2015-04-19 08:19 AM |
| MySQL毫秒值和日期的指定格式的相互转换 | Kaitlin | MySQL | 0 | 2015-04-18 11:01 PM |
| mysql 帮助文档使用 | Haddam | MySQL | 0 | 2014-11-26 06:43 PM |
| mysql安装与简单使用 | sunshine | 服务器环境搭建 | 0 | 2006-01-11 07:29 PM |
| winxp下安装全新的apache,php(5.0),mysql(5.0)... | topvip | 服务器环境搭建 | 0 | 2006-01-08 10:28 PM |