scenario is that there are a series of post (news category) in the database. Now you want to sort according to the post_date in the post table (time), view (browsing), or the likeCount of the post_like table, and read the data in batches. The limit is 25
.for example, post_date:
SELECT post.*, user.user_avatar, user.user_name,
(SELECT COUNT(*) FROM comment
WHERE comment.post_id = post.post_id) AS commentCount,
(SELECT COUNT(*) FROM post_like
WHERE post_like.post_id = post.post_id) AS likeCount
FROM post, user where post.user_id=user.user_id and post.post_date < "2018-04-05 12:12:35" order by post.post_date desc limit 25
here post_date can grab the post_date of the last entry and use it as the tag value to be obtained next time.
but the problem is: if I want to read the data in batches through view or likeCount sorting, there is no tag value in the obtained data that can be used as a tag for the next comparison.
Themysql statement is as follows:
SELECT post.*, user.user_avatar, user.user_name,
(SELECT COUNT(*) FROM comment
WHERE comment.post_id = post.post_id) AS commentCount,
(SELECT COUNT(*) FROM post_like
WHERE post_like.post_id = post.post_id) AS likeCount
FROM post, user where post.user_id=user.user_id order by likeCount desc limit 25
how do people usually solve the problem? Thank you