I want the month to show the field EstadoMateria
of the table AlumnoMateria
without duplicate records and the ones that are not showing anything, as is done in the expected result photo.
This is the result query obtained (which works well)
select IdMateria,NombreMateria
from Materias m
where not exists (select null
from AlumnoMaterias am
where am.idMateria = m.idMateria
and am.EstadoMateria in ('aprobado', 'regularizado'))
This query was made by me trying to solve my problem, it does not work because it brings duplicate and nonexistent records.
select Materias.IdMateria,NombreMateria,AlumnoMaterias.EstadoMateria
from Materias,AlumnoMaterias
where Materias.IdMateria not in
(SELECT IdMateria
FROM AlumnoMaterias
WHERE (EstadoMateria='Aprobado' or EstadoMateria='Regularizado'))