SELECT NomeD
FROM DISCIPLINA d
WHERE d.PreReqD IS NULL
AND NOT EXISTS
(SELECT 1
FROM DISCIPLINA d1
WHERE d1.PreReqD = d.CodD
AND d1.PreReqD IS NOT NULL)
SELECT NomeD
FROM DISCIPLINA d
WHERE d.PreReqD IS NULL
AND NOT EXISTS
(SELECT 1
FROM DISCIPLINA d1
WHERE d1.PreReqD = d.CodD
AND d1.PreReqD IS NOT NULL)
SELECT NomeD
FROM DISCIPLINA d
WHERE d.PreReqD IS NULL
AND NOT EXISTS
(SELECT 1
FROM DISCIPLINA d1
WHERE d1.PreReqD = d.CodD
AND d1.PreReqD IS NOT NULL)
SELECT NomeD
FROM DISCIPLINA d
WHERE d.PreReqD IS NULL
AND NOT EXISTS
(SELECT 1
FROM DISCIPLINA d1
WHERE d1.PreReqD = d.CodD
AND d1.PreReqD IS NOT NULL)
Tente:
SELECT NomeD
FROM DISCIPLINA d
WHERE d.PreReqD IS NULL
AND NOT EXISTS
(SELECT 1
FROM DISCIPLINA d1
WHERE d1.PreReqD = d.CodD
AND d1.PreReqD IS NOT NULL)
SELECT NomeD
FROM DISCIPLINA d
WHERE d.PreReqD IS NULL
AND CodD NOT INEXISTS
(SELECT PreReqD1
FROM DISCIPLINA d1
WHERE d1.PreReqD= d.CodD
AND d1.PreReqD IS NOT NULL)
Fiz um teste e aqui funciona.
SELECT NomeD
FROM DISCIPLINA
WHERE PreReqD IS NULL
AND CodD NOT IN
(SELECT PreReqD
FROM DISCIPLINA
WHERE PreReqD IS NOT NULL)
Tente:
SELECT NomeD
FROM DISCIPLINA d
WHERE d.PreReqD IS NULL
AND NOT EXISTS
(SELECT 1
FROM DISCIPLINA d1
WHERE d1.PreReqD= d.CodD
AND d1.PreReqD IS NOT NULL)