UPDATE: I got it work using the following query:
PHP Code:
mysql_query("SELECT attachment.attachmentid AS attachmentid, covertype.type AS type FROM attachment LEFT JOIN covertype ON attachment.covertype = covertype.typeid WHERE attachment.postid IN (SELECT postid FROM post WHERE threadid = " . $threadinfo['threadid'] . ") AND attachment.covertype != 0 ORDER BY attachment.covertype ASC") or die(mysql_error());