I would prefer CTE for deleting duplicate rows from sql server table
strongly recommend to follow this article ::http://codaffection.com/sql-server-article/delete-duplicate-rows-in-sql-server/
by keeping original
WITH CTE AS ( SELECT *,ROW_NUMBER() OVER (PARTITION BY col1,col2,col3 ORDER BY col1,col2,col3) AS RN FROM MyTable ) DELETE FROM CTE WHERE RN<>1
without keeping original
WITH CTE AS (SELECT *,R=RANK() OVER (ORDER BY col1,col2,col3) FROM MyTable) DELETE CTE WHERE R IN (SELECT R FROM CTE GROUP BY R HAVING COUNT(*)>1)
Related Posts:
- How can I delete using INNER JOIN with SQL Server?
- T-SQL split string
- SQL Query with NOT LIKE IN
- Conversion of a varchar data type to a datetime data type resulted in an out-of-range value in SQL query
- Conversion of a varchar data type to a datetime data type resulted in an out-of-range value in SQL query
- How can I get column names from a table in SQL Server?
- sql query to return differences between two tables
- How to select the last record of a table in SQL?
- Inserting multiple rows in a single SQL query? [duplicate]
- SQL query to get the employee name and their manager name from the same table
- Rename column SQL Server 2008
- Efficiently convert rows to columns in sql server
- How to turn IDENTITY_INSERT on and off using SQL Server 2008?sql-server-2008
- The SQL OVER() clause – when and why is it useful?
- Update multiple columns in SQL
- SQL Server IF EXISTS THEN 1 ELSE 2
- T-SQL split string based on delimiter
- Finding duplicate values in a SQL table
- SQL Query with SUM with Group By
- How do I perform an IF…THEN in an SQL SELECT?
- SQL update from one Table to another based on a ID match
- An attempt was made to access a socket in a way forbidden by its access permissions
- How to drop all tables from a database with one SQL query?
- SQL Server : Arithmetic overflow error converting expression to data type int
- How to calculate percentage with a SQL statement
- How do I do multiple CASE WHEN conditions using SQL Server 2008?
- Query comparing dates in SQL
- What is the meaning of the prefix N in T-SQL statements and when should I use it?
- Delete all the records
- Query error with ambiguous column name in SQL
- How to drop all tables from a database with one SQL query?
- How to find sum of multiple columns in a table in SQL Server 2005?
- Invalid length parameter passed to the LEFT or SUBSTRING function
- SQL Server WITH statement
- SQL Server Insert if not exists
- CREATE TABLE IF NOT EXISTS equivalent in SQL Server
- SQL Server: Invalid Column Name
- How to group by month from Date field using sql
- Is there a combination of “LIKE” and “IN” in SQL?
- How do I do multiple CASE WHEN conditions using SQL Server 2008?
- Search text in stored procedure in SQL Server
- Arithmetic overflow error converting numeric to data type numeric
- Remove duplicate rows in MySQL
- MS SQL compare dates?
- MS SQL compare dates?
- How do I fix ‘Invalid character value for cast specification’ on a date column in flat file?
- Determine ROW that caused “unexpected end of file” error in BULK INSERT?
- Determine ROW that caused “unexpected end of file” error in BULK INSERT?
- Sql query to insert datetime in SQL Server
- What is the maximum characters for the NVARCHAR(MAX)?
- Using RegEx in SQL Server
- How to write a SQL DELETE statement with a SELECT statement in the WHERE clause?
- I got error “The DELETE statement conflicted with the REFERENCE constraint”
- Microsoft OLE DB Provider for SQL Server error ‘80004005’
- Bulk load data conversion error (truncation)
- How to format a numeric column as phone number in SQL
- SQL – WHERE (X, Y) IN (A, B)
- SQL: IF clause within WHERE clause
- Can I use multiple “with”?
- How to delete from multiple tables in MySQL?
- Backup a single table with its data from a database in sql server 2008
- how to increment integer Columns value by 1 in SQL
- How can I group by date time column without taking time into consideration
- Arithmetic overflow error converting varchar to data type numeric. ’10’ <= 9.00
- SQL- Ignore case while searching for a string
- Comma separated results in SQL
- SHOWPLAN permission denied in database ‘tempdb’. in sql server 2008
- Filter data based on date in sql
- Varchar invalid for Sum operator
- Using Excel VBA to run SQL query
- What’s the best way to dedupe a table?
- What is tableName.* in SQL
- Delete duplicate rows from wordpress database where a column is duplicate in phpmyadmin
- $wpdb->prepare with ON DUPLICATE KEY UPDATE
- SQL query: select duplicate posts – but using duplicate meta [duplicate]
- Alter SQL query to return posts with unique custom field value, no duplicate values
- MySQL Error: : ‘Access denied for user ‘root’@’localhost’
- What’s the best way to search for a UPC code in a Database?
- MySQL Error: : ‘Access denied for user ‘root’@’localhost’
- What is the difference between “INNER JOIN” and “OUTER JOIN”?
- What is the difference between “INNER JOIN” and “OUTER JOIN”?
- What is the difference between UNION and UNION ALL?
- Selecting COUNT(*) with DISTINCT
- Case in Select Statement
- What is a stored procedure?
- ORA-00904: invalid identifier
- SQL WITH clause example [duplicate]
- What is an index in SQL?
- What do Clustered and Non-Clustered index actually mean?
- Removing duplicates in lists
- Unknown column in ‘field list’ error on MySQL Update query
- Unknown column in ‘field list’ error on MySQL Update query
- SQL Inner-join with 3 tables?
- The wait operation timed out. ASP
- What is SELF JOIN and when would you use it? [duplicate]
- The wait operation timed out. ASP
- Conversion failed when converting date and/or time from character string while inserting datetime
- Self Join to get employee manager name
- How do I UPDATE from a SELECT in SQL Server?
- SQL error “ORA-01722: invalid number”