I am working on some forum like database
The structure is like that
post
---------
id
user
---------
id
user_like_post
---------------
id
post_id
user_id
The user_like_post is for a "like" function just similiar to facebook like. The problem is I would like to list out the post data, showing how many like for each post.
Result of post_list:
post_id total_user_like
1 5
2 3
4 0
Like the above, how to query like that? Thanks for helping.
You only need to query your user_like_post
table like so:
select post_id,COUNT(*) AS total_user_like from user_post_like GROUP BY post_id
EDIT: and here is a SQLFiddle for you to try it out: http://sqlfiddle.com/#!2/5137c/4