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
- error, string or binary data would be truncated when trying to insert
- Teradata: how to convert varchar value (format ‘dd.mm.yyyy’) to date (format ‘yyyy-mm-dd’ )?
- How Stuff and ‘For Xml Path’ work in SQL Server?
- The multi-part identifier could not be bound
- What does the following Oracle error mean: invalid column index
- Simple way to calculate median with MySQL
- How can I import an Excel file into SQL Server?
- Creating a search form in PHP to search a database?
- The ALTER TABLE statement conflicted with the FOREIGN KEY constraint
- SQL – The conversion of a varchar data type to a datetime data type resulted in an out-of-range value
- Error 1046 No database Selected, how to resolve?
- What is it exactly a BLOB in a DBMS context
- What represents a double in sql server?
- Why do table names in SQL Server start with “dbo”?
- updating table rows in postgres using subquery
- SQL WHERE.. IN clause multiple columns
- Retrieving custom fields with $wpdb->get_results
- cron job to auto delete posts of a specific post type older than x days
- How can I prevent certain custom roles from seeing other custom roles on the user list page?
- Why this query is not showing any result on wordpresss home page?
- How to delete duplicate records in wp_postmeta database table?
- making php value numeric
- Storing huge number of users in wordpress
- How to add chunk of php, html, and sql code to variable an append to $content