Azu Posted October 31, 2007 Share Posted October 31, 2007 Hello.. can somebody please tell me why this is giving me a syntax error and how to fix it? select * from table group by row order by count(group(row)) Quote Link to comment Share on other sites More sharing options...
trq Posted October 31, 2007 Share Posted October 31, 2007 Because it is syntactly incorrect. COUNT returns a number, do you have a filed named with that number? Quote Link to comment Share on other sites More sharing options...
Azu Posted October 31, 2007 Author Share Posted October 31, 2007 Okay I have a table like this ID UserID Stuff 1 3 Blah 2 5 Blah 3 1 Blah 4 3 Blah 5 9 Blah 6 20 Blah 7 3 Blah 8 15 Blah 9 5 Blah etc And I want the query to return this 3,3 5,2 (the rest),1 But I can't get it to work :s Quote Link to comment Share on other sites More sharing options...
svivian Posted October 31, 2007 Share Posted October 31, 2007 I think you just need count(row) rather than count(group(row)) but I'm not sure. Can you explain in more detail how you want that output (3,3 / 5,2), where you're getting those number from? Do you want to obtain the number of times each UserID is used? Quote Link to comment Share on other sites More sharing options...
fenway Posted October 31, 2007 Share Posted October 31, 2007 Sounds like you want: SELECT UserID, COUNT(ID) FROM yourTable GROUP BY UserID Quote Link to comment Share on other sites More sharing options...
Azu Posted October 31, 2007 Author Share Posted October 31, 2007 Thanks guys! ^^ Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.