Home Forums SQL Server 2008 T-SQL (SS2K8) Delete records in group - but not all RE: Delete records in group - but not all
imex
Ten Centuries
Points: 1234
More actions
December 7, 2012 at 9:43 am
#1566680
Hi,
Try:
with CTE as
(
select
bookid,
ROW_NUMBER() OVER(PARTITION BY Location ORDER BY bookid DESC) as RowNum
from MyTable
)
delete from MyTable
from MyTable as t
join CTE as c
on c.bookid = t.bookid and c.RowNum > 1
Hope this helps.