Anonymous
public text v1 · immutableSELECT
T.id AS tid,
T.title,
P.id AS pid,
P.time,
U.username,
U.id as uid,
(
SELECT COUNT(id)
FROM tv_forum_readposts
WHERE userid=U.id
AND threadid=T.id
AND lastpostread=P.id
) AS `read`
FROM tv_forum_threads T
LEFT JOIN tv_forum_posts P
ON T.last_post = P.id
RIGHT JOIN tv_users U
ON P.userid = U.id
WHERE T.category = 1
ORDER BY
P.time DESC,
P.id DESC
LIMIT 1