Remove duplicate rows without unique identifier
To remove duplicate rows from a table that do not have a unique identifier column, you can use a CTE (common table expression) in conjunction with ROW_NUMBER().
Solution:
Please consider the following inquiry:
<code class="language-sql">WITH CTE AS ( SELECT [col1], [col2], [col3], [col4], [col5], [col6], [col7], RN = ROW_NUMBER() OVER (PARTITION BY col1 ORDER BY col1) FROM dbo.Table1 ) DELETE FROM CTE WHERE RN > 1;</code>
This query does the following:
Result:
The result of the query is a table with duplicate rows removed, retaining only the first occurrence of each unique row. This is achieved without requiring a unique identifier column in the original table.
The above is the detailed content of How to Delete Duplicate Rows in SQL Without a Unique Identifier?. For more information, please follow other related articles on the PHP Chinese website!