How to select data that is not saved in a record?

0

Greetings, I explain what I'm trying to do: I have students enrolled in courses. But the system must have the ability that a single student can be in 1 or more courses, the problem is not that because when I register other courses the same student does it well, here comes my need, when I'm going to enroll another course to a student I show the courses available through a select, but it turns out that in the select shows me the course or courses in which the student is already enrolled, should show only the courses in which he is not enrolled, I know that that has to do something with the DISTINCTROW, but in reality I do not know how to raise my SQL statement, in what refers to the tables in the database I will leave the image of where I bring the available courses, the student table, and the table where I keep the inscriptions.

    
asked by 26.08.2017 в 00:21
source

1 answer

0

The solution is not a JOIN, what you should do is a query to the table of CURSOS_ABIERTOS together with a condition to which a subselect of the different courses to which the student applies is applied is registered in the INSCRITOS table:

SELECT* FROM CURSOS_ABIERTOS AS C
WHERE C.id NOT IN (
    SELECT I.id_curso FROM INSCRITOS AS I
    WHERE I.id_student = 'TuEstudiante'
)

The subselect returns the courses where it is already registered. Regards, sorry for the previous answer.

    
answered by 26.08.2017 / 00:34
source