Yes - you either need to enter the date_of_entry field or another vector field, for example IDENTITY
. For example, if the Id
column is your INT IDENTITY
, then your query would look like this:
;WITH cte AS (SELECT ROW_NUMBER() OVER (PARTITION BY person_id, date_work, hours ORDER BY ( SELECT Id DESC)) RN FROM work_hours) DELETE FROM cte WHERE RN > 1
Of course, it is valid if no one changes the values ββin the IDENTITY
column
And if your conditions are suitable, then you can use the Hours
column as your vector field in the grouping range person_id, date_work
And even the best way is to have UNIQUE INDEX
over the columns person_id, date_work, hours
, then there will be no way to add duplicates.
Oleg Dok
source share