Click here to Skip to main content
15,887,998 members
Please Sign up or sign in to vote.
3.67/5 (2 votes)
See more:
Hi
Iam trying to select a users and count of users from a table.
Below is my query.
SQL
SELECT username,mobileno, count( username) AS count
FROM table
GROUP BY userid
HAVING count( username) <=5
ORDER BY count DESC



The above code returns me Error
Please anyone correct me...
Posted
Comments
CoderPanda 24-Mar-14 5:36am    
"From table" should have the actual table name and not the word "table".

If that is not the case then please share the actual error.

1 solution

You haven;t mentioned the error. But I guess you will need to include mobileno in Group By statement as you are using it in the select statement. So your updated query will be:
SQL
SELECT username,mobileno, count( username) AS count
FROM table
GROUP BY userid, mobileno
HAVING count( username) <=5
ORDER BY count DESC
 
Share this answer
 
Comments
Priyanka Sundaraj 24-Mar-14 5:38am    
Thanks for the solution
Maciej Los 24-Mar-14 11:04am    
+5!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900