Given a table similar to this one called VehicleUser:
VehicleUserId | VehicleId | UserId1 | 1001 | 22 | 1001 | 23 | 1001 | 24 1001 | 35 & ββnbsp; | 1001 | 36 | 1001 | 3
How to write a query that can remove duplicates? lines 2 and 3 are identical to line 1, with the exception of another VehicleUserId, and lines 5 and 6 are identical to 4, with the exception of another VehicleUserId.
;with cte as ( select row_number() over (partition by VehicleId, UserId order by VehicleUserId) as rn from VehicleUser) delete from cte where rn > 1;
exists, :
exists
delete v1 from VehicleUser v1 where exists ( select * from VehicleUser v2 where v1.VehicleId = v2.VehicleId and v1.UserId = v2.UserId and v1.VehicleUserId > v2.VehicleUserId )
, , , delete select:
delete
select
select * from VehicleUser v1 where exists ( ...
, , .
:
select vehicleid, userid, min(vehicleuserid) as min_id from vehicleuser group by vehicleid, userid
, -, , , , VehicleUser VehicleUser, .
.
, .
, , , , VehicleUserId.
select VehicleId, UserId from VehicleUser group by VehicleId, UserId having count(*) > 1
VehicleId/UserId, .
Source: https://habr.com/ru/post/1787740/More articles:django SelectDateWidget Years in reverse order - djangoWhat is C # the most efficient Delphi TStringList analogue? - objectHas Microsoft changed the way a string is passed as a parameter in ASP.NET MVC 3? - asp.net-mvc-3smell of synchronization code? - synchronizationproblem with primerfaces gmap tag - primefacesHow to get the ratio of the width x height of the image on the disk / file? - c #Storing NULL instead of empty row columns - .netHTML source displayed in Firebug in standard browser "View Source"? - domHow does VirtualizingStackPanel decide when to unload (delete?) Virtualized controls? - wpfUse default LLVM compiler for all Xcode projects? - iphoneAll Articles