How do JOIN in 4 tables or more?

Asked

Viewed 4,332 times

4

I need to make a select on four tables but I’m having a headache with it, follows the image of how they are related: inserir a descrição da imagem aqui

It would be something like :

SELECT integrantes.id_integrante,
       integrantes_documento.nome_integrante,
       integrantes_endereco.cep_integrante,
       votos_uniforme.voto_uniforme1,
       votos_uniforme.voto_uniforme2,
       votos_uniforme.voto_uniforme3
  FROM integrante

Just missing the JOIN’S, someone can help me?

  • Which fields you need to be listed?

  • 1

    The Join in thesis, does not change, you just put JOIN table (tbl_select.id = tbl_join.id)...

  • I put in the SELECT citation what would be the fields, would be to give an example ?

1 answer

5


Just use INNER JOIN (or LEFT JOIN)

SELECT integrantes.id_integrante, integrantes_documento.nome_integrante, 
  integrantes_endereco.cep_integrante, votos_uniforme.voto_uniforme1, 
  votos_uniforme.voto_uniforme2, votos_uniforme.voto_uniforme3 
FROM integrantes 
inner join integrantes_contato
  on integrantes_contato.id_integrante = integrante.id_integrante
inner join integrantes_documento
  on integrantes_documento.id_integrante = integrante.id_integrante
inner join integrantes_endereco
  on integrantes_endereco.id_integrante = integrante.id_integrante
inner join votos_uniforme
  on votos_uniforme.id_integrante = integrante.id_integrante
  • It shows this error: #1054 - Column 'integral.id_integral' unknown in 'on clause'

  • 1

    changes its member to the right name of the table or be members in all on

  • It worked here, thank you

Browser other questions tagged

You are not signed in. Login or sign up in order to post.