Query Database between tables

0

Database has 4 tables

tabela 1
|escola|descricao|

tabela 2
|matricula|nome|estado|

tabela 3
|matricula|escola|posicao|

tabela 4
|matricula|diretor|nome

I need to do a search by state (in table 2) and return the results:

  

Enrollment, name, school and description

Can anyone help me? I tried to be clear on what was possible.

    
asked by anonymous 09.04.2018 / 17:08

1 answer

3

You will need the JOIN clause, which closely matches search results based on search criteria.

In this case, the query would look like:

SELECT
    TB2.matricula,
    TB2.nome,
    TB1.escola,
    TB1.descrição
FROM
    tabela2 AS TB2
    JOIN tabela3 AS TB3 ON TB3.matricula = TB2.matricula
    JOIN tabela1 AS TB1 ON TB1.escola = TB3.escola;
    
09.04.2018 / 17:15