sql - MySQL Find the total amount of posts per user -


I have a database with the following two tables, USERS, POSTS I search one way To get count of how many posts the user is doing

  User Post + ---- + ------ + + ---- + ------ --- + --------- - + | ID | Name | | ID | User_id | Name | + ---- + ------ + + ---- + --------- + ----------- + | 1 | Bob | | 1 | 1 | Blogs ... | + ---- + ------ + + ---- + --------- + ----------- + | 2 | Gym | | 2 | 1 | Blogs ... | + ---- + ------ + + ---- + --------- + ----------- + | 3 | Joe | 3 | 2 | Blogs ... | + ---- + ------ + + ---- + --------- + ----------- +  
< P> I have tried to exclude many of the following SQL command from any success. Rather than showing the counting of posts for a single user, it shows a line with all the positions in the form of the count, click Users . Posts. Leave user

at userser.id I

  select user. *, COUNT (posts.user_id) Something like this  
  + ---- + ------ + | ID | Calculation + ---- + ------ + | 1 | 2 | + ---- + ------ + | 2 | 1 | + ---- + ------ +  

Understand this. Dodge the head

  Select user. *, Leave users by posts (posts.user_id) posts users.id = posts.user_id GROUP posts.user_id  

Comments

Popular posts from this blog

sql - dynamically varied number of conditions in the 'where' statement using LINQ -

asp.net mvc - Dynamically Generated Ajax.BeginForm -

Debug on symbian -