Return values from two columns of different tables

0

I have the STUDENTS table and the TEACHERS table, there are more teachers than students, I wanted to conduct a query that brings students in one column and teachers in another and not all in one.

All in one column looks like this:

SELECT PK_PROFESSORES AS CÓDIGO_ALUNO_PROFESSOR, NOME, IF(PK_PROFESSORES != NULL, 'ALUNO', 'PROFESSOR') AS VÍNCULO
FROM PROFESSORES
UNION 
SELECT PK_ALUNO, NOME, IF(PK_ALUNO != NULL, 'PROFESSOR', 'ALUNO') AS VÍNCULO
FROM ALUNOS  

Is it possible to bring each one into a column?

    
asked by anonymous 08.06.2015 / 04:51

1 answer

2

I was able to do it here, see if that's what you need

SELECT PROFESSOR.NOME, ALUNO.NOME FROM 
( 
  SELECT @rownum_p:=@rownum_p+1 AS ROW_NUM, PROFESSORES.NOME FROM PROFESSORES, (SELECT @rownum_p:=0) r
)  PROFESSOR
LEFT JOIN 
(
   SELECT @rownum_a:=@rownum_a+1 AS ROW_NUM, ALUNOS.NOME FROM ALUNOS, (SELECT @rownum_a:=0) r
) ALUNO ON PROFESSOR.ROW_NUM=ALUNO.ROW_NUM

I basically created a "FALSE ID" and linked them.

SqlFiddle DEMO

    
08.06.2015 / 07:04