2

I found a lot of duplicated data in my SQL Server with this query

SELECT
    [MærkeID], [Model], [Årgang], [Motor Type], [Krydsmålet],
    [Centerhul], [Bolter], [Dæk], [Fælge], [ET], [vendor], COUNT(*)
FROM
    Data.Hjuldata   
GROUP BY
    [MærkeID], [Model], [Årgang], [Motor Type], [Krydsmålet],
    [Centerhul], [Bolter], [Dæk], [Fælge], [ET], [vendor]
HAVING 
    COUNT(*) > 1

enter image description here

Is there a way to delete them so there is only 1 record instead of 2 of the same?

2
  • What will be the deletion criteria? Commented Jun 18, 2016 at 21:29
  • not sure what you mean with criteria but i want it so there is just 1 of each record instead of 2 of the exact same as you can see in my no column name Commented Jun 18, 2016 at 21:30

1 Answer 1

2
WITH X AS (
SELECT
     *
     ,ROW_NUMBER() OVER (PARTITION BY 
                           [MærkeID]
                          ,[Model]
                          ,[Årgang]
                          ,[Motor Type]
                          ,[Krydsmålet]
                          ,[Centerhul]
                          ,[Bolter]
                          ,[Dæk]
                          ,[Fælge]
                          ,[ET]
                          ,[vendor] ORDER BY (SELECT NULL)) RN
FROM Data.Hjuldata )
DELETE FROM X 
WHERE RN > 1
Sign up to request clarification or add additional context in comments.

1 Comment

I was almost there :(

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.