SQL and MSBI Tips and Tricks

Thursday, September 15, 2011

Drop duplicate records from table

1.
SELECT DISTINCT * INTO tab2 FROM tab1 — distinct of all columns
DROP TABLE tab1
EXEC sp_rename 'tab2','tab1'

2.
WITH T1 AS (SELECT ROW_NUMBER ( ) OVER ( PARTITION BY ID, FNAME, LNAME ORDER BY ID ) AS RNUM FROM DUPLICATE )
DELETE FROM T1 WHERE RNUM > 1
Posted by Venkata Rami Reddy at 12:27 PM
Email ThisBlogThis!Share to XShare to FacebookShare to Pinterest

No comments:

Post a Comment

Newer Post Home
Subscribe to: Post Comments (Atom)

Blog Archive

  • ►  2014 (7)
    • ►  July (2)
    • ►  February (3)
    • ►  January (2)
  • ►  2013 (17)
    • ►  November (7)
    • ►  September (7)
    • ►  June (3)
  • ►  2012 (4)
    • ►  February (3)
    • ►  January (1)
  • ▼  2011 (18)
    • ►  December (3)
    • ►  November (2)
    • ►  October (1)
    • ▼  September (12)
      • Split functions
      • Error Handling in SP
      • Finding Dependent Tables
      • DB space Findings
      • Queries for Checking OLAP instances
      • Providing User permissions on DB
      • Send mail with HTML Table format in subject area
      • sessionid,Command and Percentage complete in SQL S...
      • Row Count of All Tables in a Database and size of ...
      • Code for Result in single row from multiple row table
      • Performance Considerations for SSIS
      • Drop duplicate records from table

Pages

  • Home

About Me

Venkata Rami Reddy
View my complete profile

Followers

Simple theme. Powered by Blogger.