worth2talk Posted May 20, 2007 Share Posted May 20, 2007 Hi, I have been trying to get the rid of this issue... but unable to do.... so thought to post it here... i have created a database for authors and books.... as below Author | Book ----------|---------- Peter | book1 Richard | book2 John | book3 Greg | book4 Mark | book5 Peter | book6 Peter | book7 John | book8 Steve | book9 I want to count the top 3 authors who wrote maximum books.... (eg, peter (3), john(2), Greg (1)) anyone have idea how to achieve this ?? Quick response will be appreciated ...! Thanks in advance ..!! Jm Quote Link to comment https://forums.phpfreaks.com/topic/52203-solved-how-to-count-the-data/ Share on other sites More sharing options...
Wildbug Posted May 20, 2007 Share Posted May 20, 2007 SELECT author,COUNT(book) FROM yourtable GROUP BY author ORDER BY COUNT(book) DESC LIMIT 3; You may also wish to add another ORDER BY column to have a well-defined order clause (in cases of COUNT(book) being the same). Quote Link to comment https://forums.phpfreaks.com/topic/52203-solved-how-to-count-the-data/#findComment-257593 Share on other sites More sharing options...
worth2talk Posted May 20, 2007 Author Share Posted May 20, 2007 Wow.... It works..... Thanks a lot wildbug ..... you did a gr8 help to me.... Thanks again ...!! Quote Link to comment https://forums.phpfreaks.com/topic/52203-solved-how-to-count-the-data/#findComment-257681 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.