select distinct(a.h_id) as idhora, b.h_horaturn as horaturn  from tb_horaprog a inner join tb_horario b on a.h_id = b.h_id where a.j_id='1' and a.hp_idserva='1'
and a.uap_anno='2011' and a.uap_mes='9' and a.tp_id='1' and a.a_id='1' and a.ga_id='9' order by


select distinct(a.h_id) as idhora, b.h_horaturn as horaturn, (select o_idturn from tb_ordena where o_turn=b.h_horaturn) as tt
from tb_horaprog a inner join tb_horario b on a.h_id = b.h_id where a.j_id='1'
and a.hp_idserva='1' and a.uap_anno='2011' and a.uap_mes='9' and a.tp_id='1' and a.a_id='1' and a.ga_id='9' order by tt