J
J
Jonny Mirzayev2017-04-10 00:45:50
PHP
Jonny Mirzayev, 2017-04-10 00:45:50

How to pull out posts where 'likes > 10' (likes in another table, posts in another)?

Good day. Help a newbie, I can't figure out how to organize this.
There is a _Likes table, it has 3 fields ("user_id", "post_id" which user put @ like on which post and ID) b45da22ffbbc4402896e23dbdd6e4c92.jpg
and there is also a _posts table, it has a lot of things and of course that post_id
37035698a4624d989948694b5191c386.jpg
I want to pull out posts that scored more than 10 likes. How can I do it ?
how? php or sql query? show examples please indicate the correct path

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
vvovas, 2017-04-10
@jony7788

I'm working with MS Sql server, not MySQL, so your syntax may be different, but the idea is this:
Make a grouping in the likes table by post_id
you will get post_id's that have more than 10 likes. You can then use this as a subquery.

S
SimBioT19, 2017-04-10
@SimBioT19

You approached this issue from the wrong side.
You need to have a like counter in the post table and add 1 to it when the user likes it.
Then posts with likes > N will be easier to get.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question