i use sql to delete duplicate record but it is not working. can anyone help me.
my sql is
delete from VehicleInfoForParts where
Stock_Code not in
(
select max(Stock_Code) from VehicleInfoForParts group by stock_code,makeid,modelid
)
thanks
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If you’re on SQL SErver 2005 and up, you can use a CTE (Common Table Expression) do achieve this:
Basically, the
SELECTstatement inside the CTE groups your data by (stock_code, makeid, modelid) – i.e. each “group” of those three elements gets a consecutive row_number starting at one. The data is sorted bystock_codedescending, so the largest number is the first one, the one withRowNum = 1– so anything else (with aRowNum > 1) is a duplicate and can be deleted.