how to show queries of 2 tables in a single table with MySQL?

1

I have these tables

Student

1. Id
2. Nombre
3. Apellido
4. documento      --es numerico
5. Id_escuela     --numerico pero enlaza a Escuela

School

1. Id_escuela       ---enlace
2. Nombre_escuela 

Here my question, I want that in a single table you can only see this data

1. Nombre
2. Apellido
3. Nombre_escuela

How can I do it ?, I'm new to SQL and I need it to be able to show it in a visual basic datagridview, thank you very much in advance.

    
asked by royer 15.11.2018 в 21:54
source

2 answers

1

It's a simple query using JOIN (inner join)

SELECT a.Nombre, a.Apellido, e.Nombre_escuela
FROM Alumno a
JOIN Escuela e on a.Id_escuela = e.Id_escuela
    
answered by 15.11.2018 / 21:58
source
2

With a join between the two tables it should be enough in this way

SELECT Alumno.Nombre, Alumno.Apellido, Escuela.Nombre_escuela
FROM Escuela
JOIN Alumno ON Escuela.Id_escuela = Alumno.Id_escuela;

EXPLANATION

The Join or Inner Join will look for the matches that exist between the table on the right with the records in the table on the left and join them in a final result; in this case the crossing is made by means of the primary key in Escuela and the foreign key in Alumno

You must bear in mind that the Inner Join will only show the results on the left that have a record associated with the table on the right; discarding those who do not comply with this agreement

Also keep in mind that I used the syntax of NombreTabla.nombreColumna to send call to each required value

    
answered by 15.11.2018 в 21:59