I have two tables that do not relate. One is of reports, where it contains the name of teachers and their respective subject, the other table is called login, which contains credentials of each teacher, their privilege and also their respective subject.
The idea of the login table is that, with teacher access, it can view all the teachers in the report table when the subject matter is the same as that of the logged in teacher, and that the teacher privilege is also a teacher's
TABLE LOGIN
id
nome
materia
privilegio
REPORT TABLE
nome
materia
QUERY USED:
SELECT diga_relatorio.nome, diga_relatorio.materia, diga_login.materia
FROM diga_relatorio, diga_login
WHERE diga_relatorio.materia='{$_SESSION['digaPrivilegio']}'
AND diga_login.privilegio='professor'
GROUP BY diga_relatorio.nome
ORDER BY diga_relatorio.nome
However, this way the teachers with the position of coordinator are also returned, being wrong, since the hierarchy would be: