Getting 3 last comments from each profile

I will try to describe briefly the problem, namely: I have a page where there are about 1000 profiles. Each profile has its own comments with different dates.
What I would like to do is write a code that would take from each profile 3 last comments and add them + 6 months.
I made sample code to add those 6 months:

UPDATE sktest.wp_comment
WHERE date(wp_comment.time) BETWEEN “2015-05-01” AND “2016-06-01”

Unfortunately, I have no idea how to get only 3 last comments in each profile. Does anyone have any suggestions? Ideas?

Comments I keep in the wp_comment table, which looks like this:

To get the last three comments, order the query by “time asc” and add “Limit 3” to the query. That should sort in ascending order (oldest first), and only give you the first three rows, hence the three oldest comments.

I don’t know how you would incorporate that into your update query. It will be interesting to see, I would probably write some PHP code to do it but I am sure there’s a way without having to.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.