Yes there is. This sounds like a homework assignment, but you seem to have put some work into it. The idea is to order by the count(*)
and take the first row. The syntax in SQL Server, Sybase, and Access is:
SELECT top 1 name, surname, username
FROM users as u INNER JOIN
purchases as p
ON u.username = p.user
GROUP BY name, surname, username
ORDER BY count(*) desc;
Other databases would put a limit 1
clause after the order by
, instead of top 1
. And others may have even more arcane syntax.