Reputation: 2184
I'm trying to filter out duplicate entries (create a view) based on a key in a table. Consider the table below
I want to filter out all but one duplicate records based on EmployeeID. It doesn't matter which record is retained, although it would be nice to have a mechanism to specify a whereClause on it too. The target view looks like this
I tried using a query based on partition by however I can't quite get my result right.
Is this possible?
Thanks in advance
Upvotes: 0
Views: 30
Reputation: 1270463
The simplest method uses row_number()
:
select t.*
from (select t.*,
row_number() over (partition by employeeid order by employeeid) as seqnum
from t
) t
where seqnum = 1;
Upvotes: 1