select p.id as value, p.p_name as text,case when p_shortDesc = '' then ' ' else p_shortdesc end as q, p_comment from Pictures p inner join PictureTypes pt on p.pt_id = pt.pt_id where house_id = 3208 and Ap_ID = 15892 and pt_alias = 'plan' order by first_Pic desc, p_sort,ID desc