This code gives me a table of the unique values (without duplicates):
SELECT id, firstname, lastname, startdate, position
FROM (
SELECT id, firstname, lastname, startdate, position,
ROW_NUMBER() OVER (PARTITION BY (firstname, lastname) ORDER BY startdate DESC) rn
FROM people
) tmp
WHERE rn = 1;
What syntax would replace the current table with just the results of this one?
Alternatively, I could use WHERE rn <> 1
to get all the data I want to delete, but again, I am struggling to get the syntax of the DELETE
right using this method.