know how many posts are in another table, for each of the users

-1

I need help:

I have a user_table with the items (id, name)  and a table_post (id, user_id, etc ...)

I need that when you list the table_users, tell me how many posts each of the users has in another column something like this

id, nombre, cantidadPost
========================
1 | carlos | 0
2 | manuel | 2
3 | sofia  | 5
    
asked by Christian Valencia 22.11.2017 в 22:33
source

1 answer

0

could make a subConsultation as follows:

select
tabla_usuario.id, tabla_usuario.nombre,
( 
 select count(id) from tabla_post where tabla_post.user_id=tabla_usuario.id
) AS total_posts
from tabla_usuario

greetings

    
answered by 22.11.2017 в 22:50