SELECT columnlist, rn = ROW_NUMBER() OVER (PARTITION BY sales.salesID ORDER BY payment.paymentID) FROM sales JOIN payments ON sales.salesID=payments.salesID