please help optimize query.
I has table with fields
- 'comment_parent' for users who receive message,
- 'user_id' for user who send message,
comment_karma
set to 1 when user read message- 'updated' is datetime when user read message
How get list of favorites, who read last message on last 7 days.
Are has best way for found last message then SELECT max(updated
) ?
SELECT wc.comment_parent,wc.user_id, wc.updated FROM `wp_comments` wc
WHERE (wc.comment_parent IN (4786,322,1492,257,4760,40,41) AND wc.user_id=1)
AND wc.`comment_karma` = 1
AND updated = (SELECT max(`updated`) FROM `wp_comments` as cc WHERE cc.`user_id`= wc.user_id AND comment_parent = wc.comment_parent)
AND updated > DATE_SUB(NOW(),INTERVAL 1 WEEK)
ORDER BY wc.updated DESC LIMIT 0 , 30