To remove duplicate row data from a table, you may immediately think of using the DISINTCT keyword. However, DISINTCT can only remove rows with the same columns in the table, if you need to remove rows with multiple fields in the table (that is, some are the same and some are different), what should you do? After years of database writing experience, I have compiled the following methods for your reference:
To remove duplicate row data from a table, you may immediately think of using the DISINTCT keyword. However, DISINTCT can only remove rows with the same columns in the table, if you need to remove rows with multiple fields in the table (that is, some are the same and some are different), what should you do? After years of database writing experience, I have compiled the following methods for your reference:
To remove duplicate row data from a table, you may immediately think of usingDISINTCTKeyword,DISINTCTOnly the rows with the same columns in the table can be removed. If multiple rows with the same fields need to be removed (that is, some are the same and some are different), what should we do? After years of database writing experience, I have compiled the following methods for your reference and use.
Method 1: Suitable for returning fewer Fields
Select F1, F2, F3,MAX (F4)From tablename group by F1, F2, F3
Method 2: applicable to all fields in the returned row. You must specify different fields.
Select * from tablename t whereF4= (SelectMAX (F4)From TABLENAME where T. F1 = F1 and T. F2 = F2 and T. F3 = F3)
Method 3: This method is applicable to all fields in the returned row. You must specify different fields to [find the row to be removed]
SELECT T1. * from tablename as T1, (SELECT F1, F2, MAX (F3)AS F3 from tablename group by F1, F2 having count (*)> 1) AS T2
WHERET1.F3 AND T1.F1 = T2.F1 AND T1.F2 = T2.F2
Http://www.zuowenjun.cn/post/2014/08/02/10.html