I have a database with two tables, Users and Posts. I’d like to write a php script to list, in order, the top 20 usernames with the number of posts they’ve made. The username field is cUsername in the Users table. The Users table intUserID field and the Posts table’s intPosterID field correspond to eachother.
Any help would be much appreciated. Thanks!
Use GROUP BY and count. This will get you a list of user IDs to their counts:
You can use the result in a subquery:
To use it in a PHP script: