juliaroje86
juliaroje86

Reputation: 147

getting count of players from mysql

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.

table: [users]

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

COUNT_PLAYERS = 1

Upvotes: 2

Views: 223

Answers (1)

Xaraxia
Xaraxia

Reputation: 329

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 if you wanted it grouped:

SELECT COUNT(*) AS count_players FROM users GROUP BY rank 

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

Upvotes: 0

Related Questions