Delete duplicate records in a table, leaving only one entry:
Delete from where inch (Select* from,selectmaxfromgroup by having Count > 1 as B);
Instance:
2. When you want to create a unique index for a table, you need to delete duplicate records because there are duplicate records in the table that cannot be made.
Example Table Dept
Id_no id_name ' AAA ' 101 ' BBB ' 102 ' CCC ' 103 ' DDD ' EEE ' ' FFF ' 103 ' GGG '
Write a (or a set) SQL statement to delete the duplicate rows, but one row is required in the repeating line,
As in the table above, id_no=100 need to delete 2 rows, keep one row, id_no=101 need to delete one row to keep a row id_no=102 and 103 do not delete
Delete from where not inch Select * from (selectmaxfromgroupby haveCount(id_ NO)>1) b);
But my needs are not the same,
| ID | Createtime | Labid | PubId |
+-–+ ——————— + ——-+ ———————————— –+
| 171 | 2014-05-22 21:49:11 | 1 | d4165953-2245-4b8c-b21d-8c08d519f66e |
| 172 | 2014-05-22 21:49:11 | 2 | d4165953-2245-4b8c-b21d-8c08d519f66e |
| 173 | 2014-05-22 21:49:11 | 6 | d4165953-2245-4b8c-b21d-8c08d519f66e |
| 174 | 2014-05-22 21:49:11 | 5 | d4165953-2245-4b8c-b21d-8c08d519f66e |
| 175 | 2014-05-22 21:49:11 | 2 | d4165953-2245-4b8c-b21d-8c08d519f66e |
| 176 | 2014-05-22 21:49:11 | 6 | d4165953-2245-4b8c-b21d-8c08d519f66e |
| 177 | 2014-05-22 21:49:11 | 5 | d4165953-2245-4b8c-b21d-8c08d519f66e |
| 178 | 2014-07-03 15:20:07 | 2 | D5308254-3b52-4ada-8e10-16b6a764c5e5 |
| 179 | 2014-07-03 15:36:00 | 2 | d4bc80b4-b57b-4049-9ab3-8f45102fae91 |
| 180 | 2014-07-04 21:05:26 | 4 | f8ccee8f-d93c-41cc-8d2f-28ada7ea4b07 |
I need to delete the same duplicate records as the Labid and pubid, as long as labid and pubid have a different one than the duplicate records.
Delete from where not inch Select * from (Selectfromgroup by pubid,labid) b);
MySQL delete duplicate records only keep one bar