刷新数据库表

时间:2012-09-04 07:45:59

标签: sql

我有一个表,它填充了重复的行。我需要删除所有重复的行来刷新表。我可以用写作程序来做。它有什么最快的方式吗?

1 个答案:

答案 0 :(得分:0)

DELETE MyTable 
FROM MyTable
LEFT OUTER JOIN (
   SELECT MIN(RowId) as RowId, Col1, Col2, Col3 
   FROM MyTable 
   GROUP BY Col1, Col2, Col3
) as KeepRows ON
   MyTable.RowId = KeepRows.RowId
WHERE
   KeepRows.RowId IS NULL