$sql = "select t.ID_TOPIC,t.ID_BOARD,m.ID_TOPIC,m.ID_MSG,m.subject,IFNULL(a.ID_ATTACH,0) AS ID_THUMBS,a.ID_MSG
from $prefix1 AS t
LEFT JOIN $prefix2 AS m ON (t.ID_TOPIC=m.ID_TOPIC)
LEFT JOIN $prefix3 AS a ON (m.ID_MSG=a.ID_MSG AND a.ID_THUMB = 0)
where t.ID_BOARD IN($board) order by t.ID_TOPIC DESC limit $topic,$list ";