0
I have the STUDENTS table and the TEACHERS table, there are more teachers than students, I wanted to perform a consultation that brings students in one column and teachers in another and not all in one.
Everyone in a column was 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
There is the possibility to bring each one in a column?
Just out of curiosity why do you do this
IF
?– Maicon Carraro
How is the relationship of your tables?
– Maicon Carraro
Because as everything returned in a column, I wanted to differentiate students from teachers, the IF is a new column that says whether it is teacher or student. hehehe
– rodrigom
Teachers and students are not related.
– rodrigom
And why not make a Cartesian product? Example
SELECT * FROM ALUNOS, PROFESSORES
– Maicon Carraro
Returned repeated data, even using distinct.
– rodrigom