How to perform INNER JOIN with 3 tables using MySQL?

2

I have a question with a INNER JOIN query, in my Database I have 3 tables that are the following:

Its structure is the following table educational_level be related to the grantee table and the grantee table is related to the grading table. The problem is that wanting to get information from the three tables through PHP does not return any value, the code is as follows:

$sql_calificaciones = "SELECT becarios.*, nivel_educativo.nivel, calificaciones.calificacion
                            FROM calificaciones
                                INNER JOIN becarios
                                    ON calificaciones.id_becario = becarios.id_becario
                            FROM becarios
                                INNER JOIN nivel_educativo
                                    ON becarios.id_nivel = nivel_educativo.id_nivel";

$registros = obtenerRegistro($sql_calificaciones, $conecta);

if ($registros !== false) 
{
    echo var_dump($registros);
}

Greetings.

    
asked by Ivan18 18.10.2018 в 19:54
source

2 answers

2

The correct way to execute the JOIN would be as follows:

SELECT becarios.*, nivel_educativo.nivel, calificaciones.calificacion
    FROM calificaciones
       INNER JOIN becarios ON calificaciones.id_becario = becarios.id_becario
       INNER JOIN nivel_educativo ON becarios.id_nivel = nivel_educativo.id_nivel

The inner join are concatenated, scholarship members join on qualifications and educational level on scholarship holders and qualifications, and so you could do it consecutively with more tables.

I hope it's useful for you.

    
answered by 18.10.2018 / 20:37
source
0

When you joins, you only have to put the first FROM. The second one was over.
Try this way:

$sql_calificaciones = "SELECT becarios.*, nivel_educativo.nivel, calificaciones.calificacion
                            FROM calificaciones
                                INNER JOIN becarios
                                    ON calificaciones.id_becario = becarios.id_becario
                                INNER JOIN nivel_educativo
                                    ON becarios.id_nivel = nivel_educativo.id_nivel";

$registros = obtenerRegistro($sql_calificaciones, $conecta);

if ($registros !== false) 
{
    echo var_dump($registros);
}

To learn how to use the joins correctly you can click here

    
answered by 18.10.2018 в 20:00