I was reviewing a "top 3 products per category" report last week and found a bug that had been live for months. One category showed four products. Another showed the same product twice. The query used RANK() . It should have used ROW_NUMBER() . They look interchangeable in a tutorial and behave completely differently the moment your data has ties. The setup Here is a small sales table with an obvious tie β€” two products in the same category sold 120 units: CREATE ...