5
I’m having trouble making an appointment. The situation is as follows, I need the bank to return all the names of the disciplines that have no prerequisites and that are not prerequisites.
This is the relationship:
/* Create a table */
CREATE TABLE DISCIPLINA(CodD char(2) PRIMARY KEY,
NomeD varchar(60),
CargaD int,
AreaD varchar(60),
PreReqD char(2),
FOREIGN KEY (PreReqD) REFERENCES DISCIPLINA(CodD));
/* Create few records in this table */
INSERT INTO DISCIPLINA VALUES('D1','TLP1', 2, 'Computação', 'D2');
INSERT INTO DISCIPLINA VALUES('D2','Cálculo 1', 4, 'Matemática', NULL);
INSERT INTO DISCIPLINA VALUES('D3','Inglês', 2, 'Humanas', NULL);
INSERT INTO DISCIPLINA VALUES('D4','Ed Física', 3, 'Saúde', NULL);
INSERT INTO DISCIPLINA VALUES('D5','G Analítica', 5, 'Matemática', 'D2');
INSERT INTO DISCIPLINA VALUES('D6','Projeto Final', 6, NULL, 'D1');
I tried this way and also with LEFT JOIN, but did not succeed.
SELECT DISTINCT D1.NomeD
FROM DISCIPLINA D1, DISCIPLINA D2
WHERE D1.CodD != D2.PreReqD AND D2.PreReqD IS NULL;
So you only have to return what you have NULL, right?
– Lucio Rubens
Hello Lucius, in case not. Because Calculus 1 is prerequisite of another matter, then could not return it.
– Wellington Perez