I have this select
SELECT firstname, lastname, email, brand
FROM (SELECT brand, COUNT(brand) AS choiced
FROM users
GROUP BY brand
ORDER BY `choiced` DESC
LIMIT 1) AS winner
ORDER BY RAND()
LIMIT 1
Error #1054 column firstname in field set is unknow.
I have table users, with columns id, firstname, lastname, email and brand
I need to select one (and only one) random user (firstname, lastname, email) from the users that selected the most voted brand.
So if I make:
SELECT brand, count(brand) AS choiced
FROM users
GROUP BY brand
ORDER BY choiced DESC LIMIT 1
Result is: brand JOE DOE, Choiced 47.
But I don’t know how to obteined the random user inside those 47 users.
I hope that I explained myself, English is not my first language.
3
Answers
If there will be one brand with a maximum number of votes you may try the following:
If it could be more than one brand that have the max number of votes then you may try the following:
See a demo.