$results = $db->fetchAll("
SELECT attach.*, data.*, user.username
FROM xf_attachment AS attach
INNER JOIN xf_attachment_data AS data ON
(data.data_id = attach.data_id)
INNER JOIN xf_user AS user ON
(user.user_id = data.user_id)
INNER JOIN xf_post AS post ON
(post.post_id = attach.content_id)
INNER JOIN xf_thread AS thread ON
(thread.thread_id = post.thread_id)
WHERE attach.content_type = 'post' AND thread.node_id != 3
ORDER BY attach.attachment_id desc LIMIT " . $limit . "
");