|
|
||||||
|
||||||
| Index Link To US Private Messages Archive FAQ RSS | ||||||
| Database Discussion Forum This is the place to find help resolving those nagging questions you have about implementing and using all kinds of databases. Need help writing a query? Need an opinion on Oracle? Post here! |
Share Thread: & Tags
|
||||
|
![]() |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
hi wpw
in the database there are multiple records for the same person. for example person 1 has 5 entries person 2 has 3 entries and so forth. all im trying to do is get a simple count of who has the most entries from highes to lowest. i wrote this query it works well for me but im using mysql version 5.1.33 locally. SELECT mname, COUNT(mname) FROM votes GROUP BY mname ORDER BY COUNT(mname) DESC the server this will run on uses a older version of mysql. im not sure which one though. any ideas on how i can rewrite this?
__________________
It's better to do business with me than against me! |
|
|||
|
That looks perfectly fine for whatever version of MySQL you need...certainly on MySQL 5.0, and 4.x...
Is there a reason you think it won't work? GROUP BY and COUNT are pretty standard stuff. As far as the query itself, you might want to group by the person ID (if there is one), rather than the name (in case 2 people have the same name like "John Smith"), otherwise no problem. |
|
|||
|
Thanks Uncle Dog and dmartin.
i should have mentioned that detail. I tried to run it. The error i receive is: Invalid use of group function if i run it without ORDER BY COUNT(mname) DESC it will output all the information but not in order. fyi the version of mysql that's live is 3.23.58
__________________
It's better to do business with me than against me! |
|
|||
|
Glad that worked - old MySQL versions are a little quirky in terms of the SQL they support - my guess is that expressions without aliases don't work in 3.23 with a GROUP BY...who knows.
Maybe your installation can eventually upgrade to something better supported - 3.23 (and 4.0 and 4.1) have been "end of lifed". |
![]() |
|
| Thread Tools | |
| Display Modes | |
|
|
|
WebProWorld |
Advertise |
Contact Us |
About |
Forum Rules |
MVP's |
Archive |
Newsletter Archive |
Top |
WebProNews
WebProWorld is an iEntry, Inc. ® site - © 2009 All Rights Reserved Privacy Policy and Legal iEntry, Inc. 2549 Richmond Rd. Lexington KY, 40509 |