Use FULL JOIN in Mysql

Asked

Viewed 1,199 times

0

I needed to make a query that I return in a row the data of a candidate plus the courses to which I applied, and this data is in a relational table 'tblcandidatoCurso'. After some research I tried to use FULL JOIN, but I always feel error.

Follow the query I made

SELECT DISTINCT can.idCandidato, cur.idCurso, cur1.idCurso, cur2.idCurso
FROM
tblcandidatura AS can
INNER JOIN tblcandidatocurso AS cur ON cur.idCandidato = can.idCandidato
FULL JOIN tblcandidatocurso AS cur1 ON cur1.idCandidato = can.idCandidato
FULL JOIN tblcandidatocurso AS cur2 ON cur2.idCandidato = can.idCandidato
WHERE cur.ordem = 0
AND cur1. ordem = 1
AND cur2.ordem = 2

The goal was to have something like this: inserir a descrição da imagem aqui

  • where is the "tblcandidatura " ?

  • 1

    If the relationship is between the same tables you do in the same JOIN. In your example you are creating 3 JOINS to relate the same tables.

1 answer

1


As @fleuquer-file said in the comments, you are creating 3 joins with the same table. Your sql should be equal to the question image, the first table garter with the second and the second table garter with the third.

SELECT can.idCandidato, cur.idCurso, cur1.idCurso, cur2.idCurso
FROM tblcandidatura AS can
JOIN tblcandidatocurso AS cancur ON cancur.idCandidato = can.idCandidato
JOIN tblcursos AS cur ON cur.idCurso = cancur.idCurso;

Browser other questions tagged

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