SQL Join JOIN

-1

I need to work out a query that brings the employee's registration, employee's name, and employee's city name using JOIN . But as I have no experience yet with this function, I'm stuck !! For this I have the funcionario table and the cidade table. So far I have this:

select * from funcionario, cidade

select funcionario.matfunc, funcionario.nome, cidade.nome
from funcionario, cidade
where funcionario.nome = cidade.nome

Now I'm stuck because I did not get the JOIN bid.

    
asked by anonymous 06.10.2018 / 02:45

2 answers

1

You were almost there, the comparison has to be codcid of table funcionario with codcid of table cidade .

select funcionario.matfunc, funcionario.nome, cidade.nome
from funcionario, cidade
where funcionario.codcid = cidade.codcid

This above is already a JOIN , but you can make it more explicit and easier to understand as follows:

select funcionario.matfunc, funcionario.nome, cidade.nome
from funcionario
JOIN cidade ON funcionario.codcid = cidade.codcid

In this is a very interesting question about all types of JOIN .

    
06.10.2018 / 03:45
-1

Your question is a bit confusing, post as is the structure of the two tables. and which fields you want to display.

The inner join structure would look something like this:

select * from funcionarios left outer join cidades on funcionarios.cid_cli = cidades.cod_cidade
    
06.10.2018 / 03:44