Wednesday, March 7, 2012

keeping last 10 entries by ID

Hello

my table :
Report :
R_id (PK)
RName
RDate

i am having a few 10.0000 lines and i want to keep the last 10 (or less if not in the table) rows maximum for each name

i can have 100 report by name (100 rows with the same name and of course R_id and RDate are different)

how can i do it ?

thanks a lot for helpingdelete
from Report
where R_id not in
(select top 10
R_Id
from Report Report2
where Report2.RName = Report.RName
order by RDate desc)

No comments:

Post a Comment