MySQL Find the total amount of posts per user

前端 未结 2 1843
失恋的感觉
失恋的感觉 2021-02-10 02:07

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         


        
2条回答
  •  自闭症患者
    2021-02-10 03:07

    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
    

提交回复
热议问题