Reputation: 57
Here, is just a foo example.
id user car
------ ---------------------
1 kerN eTrac
2 rSky TClea
3 ataw arahm
4 nvd lengr
5 233 yzxq2
6 kerN eTrac
7 keOr gStri
8 odev eunic
9 owsm cward
10 ielr cgabr
11 kerN eTrac
From this table, I want to fetch the user with the most cars. In this case, the result should be the user
KerN
because they have 3 eTrac
cars.
Upvotes: 0
Views: 39
Reputation: 6065
Try this:
SELECT user, COUNT(*) cars
FROM table
GROUP BY user
ORDER BY cars desc
LIMIT 1;
Upvotes: 2