Consult the names of the pilots sponsored by a Team

Asked

Viewed 98 times

1

I want to consult pilots sponsored by the 'A' team'

I’m doing like 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 you’re not returning anything, where I’m going wrong?

The model is this: inserir a descrição da imagem aqui

  • which error returns? o idpat, idequipe and nome are actually written like this in the bank? in the image you presented, are like ID_PAT, NOME_E and NOME_P.

  • In the links to be OK, but the problem may be in the data. Are you sure you have pilots associated with sponsored teams and teams named "A"?

1 answer

1


As you want the names of the pilots, best use as main table to pilotos, makes it easier to assemble 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 used the LIKE so it will bring everyone who starts with the letter A.

Browser other questions tagged

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