select ra.value, ra.ra_id, q.id as q_id, q.qid , q.parent, q.q, q.type, p.qid as pqid, if($ifstatement,'1','0') as selection , r.rpid from r, ra, q left join q p on q.parent = p.id where r.id = ra.ra_id and r.q in (3,4,5) and ra.q = q.id order by ra.ra_id ASC,selection desc;