Hello! I have a MySQL table with the columns "user" and "warningpoints" for each warning as you can see in the table above. How can I get the user which has the most warningpoints in total in PHP?
Thanks in advance.
You can use
GROUP BY and
ORDER BY and
SELECT t.user,sum(t.warningPoints) as sum_points FROM YourTable t GROUP BY t.user ORDER BY sum_points DESC LIMIT 1;
Or if there is only one record per person, no need to group :
SELECT t.user,t.warningPoints FROM YourTable t ORDER BY t.warningPoints DESC LIMIT 1;