Solved

sql mysql count

Posted on 2008-06-11
2
287 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 250 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 250 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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL Syntax Grouping Sum question 7 36
Duplicated data in GROUP_CONCAT 2 16
Getting "Invalid Operation" Error when opening a Recordset 10 33
mysql qry 1 21
'Between' is such a common word we rarely think about it but in SQL it has a very specific definition we should be aware of. While most database vendors will have their own unique phrases to describe it (see references at end) the concept in common …
PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

762 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