I am beginning to see DB, I am trying to understand how relationships work, the example I am trying to do consists of having a teacher table and a student table;
I want to query the students table, but with teacher data, that is, tell me to select all the students who have "teacherX" as their teacher.
My tables and relationship are like this:
Here I am doing select, but with the id that already contains the student table, what I want to know is how to indicate that, instead of putting the id, put the teacher's name something like ***select * from alumno where id_profesor = (select id from profesor where nombre = Gabriel)***
(I know that I don't know how to write it that way, but I don't I know how to do it).
Here are the records for my 2 tables.
You could do it this way to stop query nesting:
The way you put it is also a good idea, and it would work without any problem, only that its key is called id_profesor and the name would have to go with double quotes " "...
It would look like this:
Use an INNER JOIN to join both tables via their primary key and foreign key:
In this way you will obtain a table with the name of the teacher and all his associated students.