Skip to content
Advertisement

Delete records with duplicates and join in another table

I need to write a query (Microsoft SQL Server) to delete duplicates in the table Vehicle that have Vehicle.CarId = Car.CarId and having the same concatenation (CarId, CounterLimit, Kilometers).

Table Car:

Table Vehicle:

Could you please help me?

Advertisement

Answer

  • Joining the table
  • creating the rank based on carid,counter limit, kilometer. If all three are same it is considered as duplicate. If you need to add more or less number of columns in this criteria you can adjust this part
  • next we take just one of the above row , meaning we eliminate the duplicates using rank_1 = 1
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement