Check the names of the pilots sponsored by a Team

1

I want to consult pilots sponsored by team 'A'

I'm doing this:

SELECT piloto.nome AS NomePiloto
FROM equipe
INNER JOIN piloto
ON equipe.idequipe = piloto.idequipe
INNER JOIN patrocinador
ON patrocinador.idpat = equipe.idpat
WHERE patrocinador.nome = 'A'

But, is not returning anything, where am I going wrong?

The template is this:

    
asked by anonymous 07.09.2018 / 05:56

1 answer

1

As you want the names of the pilots, it is better to use the pilotos as the main table, so it makes it easier to mount the query .

SELECT pi.nome as piloto, eq.nome_e as equipe, pt.nome_p as patrocinador
FROM piloto pi
LEFT JOIN equipe eq ON eq.id_equipe = pi.id_equipe
LEFT JOIN patrocinador pt ON pt.id_pat = eq.id_pat
WHERE pt.nome_p LIKE 'A%'

I've used LIKE so this will bring all of them beginning with the letter A .

    
07.09.2018 / 11:24