qweqweqwe
qweqweqwe

Reputation: 343

Two Columns Sort MYSQL

I'm trying to show names in my database based on if the gender is a boy. I'm currently trying this query but it doesn't seem to work.

SELECT
  Name,
  COUNT(Name),
  Gender='Boy' AS totalNumber
FROM
  finaldb
GROUP BY
  Name,
  Gender
ORDER BY
  COUNT(Name) DESC
LIMIT 5

Any suggestions?

Upvotes: 0

Views: 46

Answers (1)

PaulG
PaulG

Reputation: 7102

I think Gender='Boy' is in the wrong place, put it after WHERE

SELECT Name, Gender, COUNT(Name) AS totalNumber FROM finaldb WHERE Gender='Boy' GROUP BY Name, Gender ORDER BY COUNT(Name) DESC LIMIT 5

A good place to read up on WHERE and SQL in general:

http://www.w3schools.com/sql/sql_where.asp

Upvotes: 1

Related Questions