I have a Database with the following two tables, USERS, POSTS I am looking for a way to get the count of how many posts a user has.
Users P
select users.*, count(posts.user_id)
from users, posts
where users.user_id = posts.user_id
group by posts.user_id
But the best way is too add a field to the users table and keep the amount of posts made by each users, and updated it whenever a post is created or deleted. Otherwise, you'll slow down your DB when it grows bigger.
Figured it out. Smacks self in head
SELECT users.*, count( posts.user_id )
FROM posts LEFT JOIN users ON users.id=posts.user_id
GROUP BY posts.user_id