getting count of players from mysql

Viewed 53

I need to get the amount of users who have rank = player

So far I tried select count(*) as count_players from users where rank = player

I'm not sure where the error is, if only in the tags and query is correct or I'm going about it completely wrong, thanks in advance for the advice!

table: [users]

id username password rank
1 john $2y$10$zYharAUmf36hVzkYUg87y.avY player
2 jane $2y$10$zYhajIUGU89887jhgUg87yKJ8G admin

COUNT_PLAYERS = 1

1 Answers

Cully below is right, it shouldn't need to be grouped when you're after a single result. You would do the following when you were after it grouped by rank (and you wouldn't do rank='player').

SELECT COUNT(*) AS count_players FROM users WHERE rank='player';

OR SELECT COUNT(*) AS count_players FROM users GROUP BY rank if you wanted it grouped.

Have you tried quoting the rank you're targeting? It's a string, not a variable.

Related