Maybe try replacing the sql with:
Code:
$sql = "
SELECT contenttypeid, tagcontent.contentid, tagcontent.contentid as threadid, thread.lastpost AS lastpost
FROM ". TABLE_PREFIX . "tagcontent as tagcontent
LEFT JOIN ". TABLE_PREFIX . "thread as thread ON (thread.threadid = tagcontent.contentid)
WHERE tagid = " . $equals['tag'] . "
ORDER BY lastpost DESC
LIMIT 20000";