I tried to get the customer that pay the maximum amount. It gave me the maximum amount but the wrong customer. what should i do?
SELECT temp.customerNumber, MAX
I don't think you need the Subquery here:
SELECT p.customerNumber, MAX(p.amount) AS max FROM payments p GROUP BY p.customerNumber ORDER BY max DESC LIMIT 1