select t1.id,t1.name,t2.id as bugID,t2.type from TABLE_PRODUCT as t1 
left join TABLE_BUG as t2 on t1.id=t2.product 
left join TABLE_PROGRAM as t3 on t1.program=t3.id 
where t1.deleted='0' and t2.deleted='0'
order by t3.`order` asc, t1.line desc, t1.`order` asc