Merge results from two tables

0

I need to make a SELECT into two tables and merge the results.

My tables are "class_tracks" and "progress_tracks". In the table "courses_aula" I have all the classes of a course. In the table "cursos_progresso" I have registration only if the client started (finishing or not) the class. That is, I need you to list all the classes in course X and display the status that is in the table "progress_tracks". If the record does not exist it should return NULL , but I am only able to merge the matching results into the two tables.

My Query is:

SELECT a.id, a.aula, p.status
FROM cursos_aulas a
LEFT JOIN cursos_progresso p ON p.id_aula=a.id
WHERE a.id_curso='$idCurso' AND p.cpfcnpj='$cpfcnpj'
ORDER BY a.sequencia

Does anyone know what I might be doing wrong?

    
asked by anonymous 14.12.2016 / 18:47

1 answer

0

In your cursors table is ID the primary key? Because in WHERE you put a.id_curso .

Try this:

SELECT
    a.id,
    a.aula,
    p. STATUS
FROM
    cursos_aulas a
LEFT JOIN cursos_progresso p ON p.id_aula = a.id
AND
    p.cpfcnpj = '$cpfcnpj'
WHERE
    a.id = '$idCurso'
ORDER BY
    a.sequencia
    
14.12.2016 / 18:51