Skip to content
Advertisement

Delete rows to keep only top values in a sql table

I am trying to have some product recommendations in my website. I have this table that i have generated but need to keep a limited amount of entries.

The table consists of these columns (filling with some random values):

How can i trucate top 10 SCORE values for each PRODUCT ID in this table?

Advertisement

Answer

Note — you did not say what platform, the following will work in SQL Server, Oracle, DB2 and others

The following statement will give you the top 10 ten rows

So then delete everything else

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement