Database query between tables

Asked

Viewed 35 times

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 state search (in table 2) and return the results:

registration, name, school and description

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

1 answer

3


You’ll need the clause JOIN, that makes precisely the junction of search results based on search criteria.

In this case, the consultation would be:

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;

Browser other questions tagged

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