Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

sql mysql count

Posted on 2008-06-11
2
Medium Priority
?
291 Views
Last Modified: 2010-03-19
SELECT COUNT(*) AS `Rows`, `Ssurname` FROM `member` GROUP BY `Ssurname` Where Rows > 2
ORDER BY `Rows` Desc


 MySQL said: Documentation
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Where Rows > 2
ORDER BY `Rows` Desc
LIMIT 0, 30' at line 1


How can icorrect the code above
0
Comment
Question by:teera
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 48

Accepted Solution

by:
hernst42 earned 1000 total points
ID: 21757859
Conditions for the grouping are named having like:

 SELECT COUNT(*) AS `Rows`, `Ssurname` FROM `member` GROUP BY `Ssurname` HAVING COUNT(*) > 2
0
 
LVL 6

Assisted Solution

by:dragos_craciun
dragos_craciun earned 1000 total points
ID: 21757865
You must write

SELECT COUNT(*) AS `Rows`, `Ssurname` FROM `member` GROUP BY `Ssurname`
HAVING COUNT(*) > 2
ORDER BY `Rows` Desc

WHERE can be used only for individual rows
For filtering on aggregates, use HAVING
0

Featured Post

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

661 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question