select distinct PROFESOR ,concat(sel.cod_cur,' ',des_cur) as CURSO, concat(sel.cod_mat,' ',des_mat) as ASIGNATURA ,sel.id_alu as CODIGO, concat(l.ape_per,' ',l.nom_per) as ESTUDIANTE from(
select distinct a.id_con , b.id_alu ,m.cod_cur,m.cod_mat,concat(p.ape_per,' ',p.nom_per) as PROFESOR
from
matgra m  
inner join persona p on p.id_per=m.id_per 
inner join alumcurso b on b.cod_cur=m.cod_cur 
left join  (select * from concepalu where id_peri=1  ) a on a.id_alu=b.id_alu and a.cod_cur =m.cod_cur and a.cod_mat=m.cod_mat
where  m.grp_con='s'
union
select a.id_con, b.id_alu ,m.cod_cur,m.cod_mat,concat(p.ape_per,' ',p.nom_per) as PROFESOR
from
matgra m 
inner join persona p on p.id_per=m.id_per  
inner join alumcurso b on b.cod_cur=m.cod_cur 
left join  (select *, 0 as id_con from concepaluadi where id_peri=1  )  a on a.id_alu=b.id_alu and a.cod_cur =m.cod_cur and a.cod_mat=m.cod_mat
where  m.con_mat='s'
) sel  
inner join alumno l on sel.id_alu=l.id_alu
inner join curso c  on c.cod_cur=sel.cod_cur
inner join grado g on g.cod_gra=c.cod_gra
inner join materia t  on  t.cod_mat=sel.cod_mat
where id_con is null 
order by PROFESOR, des_mat, ord_gra, des_cur,l.ape_per