Doubt in Select

Asked

Viewed 44 times

1

I have mysql database with some registered information and I need to search through a select Championship and Modalities that a person has no link, but I have tried several ways and I could not succeed, the most I could was to look for the modalities that there is nobody registered.

 Diagrama

  • Welcome to Stack Overflow! Your question seems to have some problems and your experience here in Stack Overflow may not be the best because of this. We want you to do well here and get what you want, but for that we need you to do your part. Here are some guidelines that will help you: Stack Overflow Survival Guide in English.

1 answer

1


Try:

SELECT modalidades.* FROM modalidades LEFT JOIN inscricoes ON (modalidades.id = inscricoes.id_modalidade)
WHERE inscricoes.id_modalidade IS NULL;

If you need the name of the championship:

SELECT modalidades.*, campeonato.* 
FROM modalidades INNER JOIN campeonato ON (modalidades.id_campeonato = campeonato.id) 
LEFT JOIN inscricoes ON (modalidades.id = inscricoes.id_modalidade)
WHERE inscricoes.id_modalidade IS NULL;

===========

Add at the end of the clause ON of inscricoes:

AND inscricoes.id_pessoa = id_da_pessoa_desejada
  • It worked perfectly both ways, as I would consult those modalities that a specific person is not enrolled?

  • I didn’t know it was possible to do this within the ON good to know, that way solved my problem and gave me new usage ideas, thank you very much!

Browser other questions tagged

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