More than one table in the query - LEFT JOIN SQL

1

SQL Help:

Query :

SELECT * FROM concursos 
LEFT JOIN concursos_categorias ON concursos.id = concursos_categorias.idConcurso 
LEFT JOIN categorias_concursos ON concursos_categorias.idCategoria = categorias_concursos.id 
WHERE concursos.id = 15
  • concursos is my table where you have all my contests
  • categorias_concursos is the table where you have all categories
  • concursos_categorias is my table where the categories of the contest

in the concursos_categorias table has the columns idConcurso and idCategoria

The query she is bringing me the categories of the contest, but I also needed to bring the other categories, not repeating the ones that have this contest.

    
asked by anonymous 22.10.2014 / 12:50

2 answers

2

SOLUTION

SELECT * FROM categorias_concursos cat 
LEFT JOIN concursos_categorias con ON cat.id = con.idCategoria and con.idConcurso = '$id' 
LEFT JOIN concursos c ON con.idConcurso = c.id
    
24.10.2014 / 01:43
0

Try to use group_by so that it chooses the repeated columns.

    
07.03.2017 / 19:23