Reputation: 108
I want to get records after a certain record, say id
is 4.
Actually I want to show posts based on likes with pagination.
So I sorted result by likes.
But I don't know how to get the next records based on id
.
Here is my code
SELECT urp.* , likes
FROM user_related_posts urp
JOIN (
SELECT post_id, COUNT(*) AS likes
FROM post_likes
WHERE STATUS =1
GROUP BY post_id
) v ON urp.post_id = v.post_id
GROUP BY post_id
ORDER BY likes DESC
LIMIT 0 , 30
Sorry I don't put image, I don't have enough credentials.
What here doing is when I order with likes, ids are unsorted,
but I want records based on id
.
Upvotes: 1
Views: 693
Reputation: 13971
You can use date_created
in your query.
SELECT *
FROM post_likes
WHERE (date_created >
(SELECT date_created
FROM post_likes AS p1
WHERE (id= 4)))
Note :
I have not added the entire code.Please use the code and edit as your requirement.
Upvotes: 0