select t1.*,t2.name, (case when t1.status = 'closed' or t1.stage = 'released' then 1 else 0 end) as done, 1 as count from TABLE_STORY as t1 
left join TABLE_PRODUCT as t2 on t1.product=t2.id 
left join TABLE_PROGRAM as t3 on t2.program=t3.id 
where t1.deleted='0' and t2.deleted='0'
order by t3.`order` asc, t2.line desc, t2.`order` asc