I have a table called 'users' and a table called 'posts'. posts table holds id information for users as a foreign key attribute. I want to select every username that corresponds to id number in posts table FROM users table. Then i will use
GROUP BY username
I wouldn't group by username, because there could be multiple users having the same name. Instead group by the user's id.
SELECT users.username, count(*) FROM users, posts WHERE users.id = posts.user_id GROUP BY users.id;