KevinM1 Posted May 11, 2010 Share Posted May 11, 2010 I was wondering how I'd go about selecting and counting database entries based on how their titles are arranged alphabetically, and how to obtain the count for all the entries associated with a particular letter. The results I'm trying to get should look something like: A (15) B (2) C (9) etc. None of the built-in string functions jump out at me, at least not in a way that I could use them in a select query. Quote Link to comment https://forums.phpfreaks.com/topic/201417-query-help-alphabetical/ Share on other sites More sharing options...
ajlisowski Posted May 11, 2010 Share Posted May 11, 2010 SELECT LEFT(UCASE(`title`), 1) AS `letter`, count(`title`) AS `count` FROM `lunapp_project_note` GROUP BY `letter` I think this should do what you want unless I misunderstood. Quote Link to comment https://forums.phpfreaks.com/topic/201417-query-help-alphabetical/#findComment-1056772 Share on other sites More sharing options...
ignace Posted May 11, 2010 Share Posted May 11, 2010 Would this work? SELECT left(field,1) AS letter, count(*) AS letter_count FROM table GROUP BY letter ORDER BY letter ASC Quote Link to comment https://forums.phpfreaks.com/topic/201417-query-help-alphabetical/#findComment-1056794 Share on other sites More sharing options...
KevinM1 Posted May 12, 2010 Author Share Posted May 12, 2010 Awesome. Thanks, guys. Quote Link to comment https://forums.phpfreaks.com/topic/201417-query-help-alphabetical/#findComment-1057224 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.