inner join repeats the data

0

Hello, good morning everyone, guys consult, I'm involved with a query, I need to show data from 3 different tables, I get it, but I repeat the data (rows), I have given several turns and I do not give the drama hehe , someone sees something strange:

CREATE DEFINER='administrador'@'%' PROCEDURE 'spMostrarHorasAtencion'()
BEGIN
SELECT
h.idHoraAtencion,
p.nombres, p.ape_pat, p.ape_mat,
h.dia,
b.numBox,
ho.hora
FROM
profesional p INNER JOIN horas_atencion h
ON p.idRegistro= h.idRegistro,
boxes_atencion b INNER JOIN horas_atencion h1
ON b.idBox = h1.idBox,
hora ho INNER JOIN horas_atencion h2
ON ho.idHora = h2.idHora;
END

Greetings to all, thanks in advance

    
asked by Nicolas Ezequiel Almonacid 30.07.2018 в 19:08
source

2 answers

0

From what I see these instantiating 3 times to the same table in the INNER JOIN, which does not make sense.

Try to normalize your syntax, try this code:

 CREATE DEFINER='administrador'@'%' PROCEDURE 'spMostrarHorasAtencion'()
 BEGIN
 SELECT
 h.idHoraAtencion,
 p.nombres, 
 p.ape_pat, 
 p.ape_mat,
 h.dia,
 b.numBox,
 ho.hora
 FROM horas_atencion h
 INNER JOIN profesional p ON p.idRegistro= h.idRegistro
 INNER JOIN boxes_atencion b ON b.idBox = h.idBox
 INNER JOIN hora ho ON ho.idHora = h.idHora;
 END

Try to put an identifier in hard, in case it brings you more than 1 data, you should enter to modify the query according to the requirement.

    
answered by 30.07.2018 / 20:51
source
-1

You have to group the data by value, I do not know how you have the table, but I guess they all have a value by which you can group them, such as a table of students, you can group by grade, group or career depending on how you drive

    
answered by 30.07.2018 в 19:10