Join between tables that are not directly related

0

I have three tables:

  • Candidate that has an ID as pk (which was invented)
  • Application that has FK for Candidate
  • ENEM that does not have any id that represents the candidate, only his / her registration and information such as color / race, municipality
  • I need to bring this PK_Candidate into the Enrollment table by doing a JOIN with the Enem table, but how do I do that if Candidate and Enem are not directly related to a unique code, just for information that repeats itself as sex?

    I tried to relate Candidate and Enem by another table that both have in common, which would be Municipality, but also did not obtain the expected result, which would be the registration number without repetition followed by the desired data.

        
    asked by anonymous 18.09.2017 / 03:54

    1 answer

    0

    It would be interesting to also put the information in the ENEM table, as you did with the CANDIDATE and REGISTRATION. But as it says in the table ENEM contains the inscription field, by this we can join with INSCRIPTION and then make a join with CANDIDATE.

    Example:

    Select 
        c.PK_CANDIDATO 
    FROM 
        ENEM e
        INNER JOIN INSCRIÇÃO i ON i.ID_INSCRIÇÃO = e.<CAMPO_DE_INSCRIÇÃO>
        INNER JOIN CANDIDATO c ON c.PK_CANDIDATO = i.FK_CANDIDATO
    
    ;
    

    Never put names of objects with special characters like "Ç", "Ã".

        
    28.03.2018 / 20:35