Use Rand and randomly assign all columns

0

I have this table (centrodb.InfoColaboradores) which has the ids of all the other tables that I make the join in the database with this data:

I have this query:

SELECT B.NomeColaborador, 
   C.Ala,
   D.Grupo,
   E.Turno

FROM centrodb.RelacaoColab AS A LEFT OUTER JOIN centrodb.InfoColaboradores AS B

ON B.Id = A.IdColab LEFT OUTER JOIN centrodb.TiposAlas AS C

ON C.Id = A.IdAla LEFT OUTER JOIN centrodb.TiposGrupos AS D

ON D.Id = A.IdGrup LEFT OUTER JOIN centrodb.H_Turno AS E

ON E.Id = A.IdTurn

WHERE E.Turno = 'M' ORDER BY RAND() LIMIT 8

How do I not get repeated these situations when generating the 8 employees of the 11 that I have in the database table?

    
asked by anonymous 31.01.2018 / 10:52

1 answer

1

In order for the names to not be repeated, just put at the end of the query before order :

GROUP BY B.NomeColaborador

The issue of other duplicate information, I believe is by the use of

left joins

See how left join works:

ieitwillbringtheinformationfromthelefttableifitisnotthesame.Trytouseonlyinnerjoin:

WhereItookpictures codeacademy

How does your query work?

SELECT B.NomeColaborador, 
   C.Ala,
   D.Grupo,
   E.Turno

FROM centrodb.RelacaoColab AS A JOIN centrodb.InfoColaboradores AS B

ON B.Id = A.IdColab JOIN centrodb.TiposAlas AS C

ON C.Id = A.IdAla JOIN centrodb.TiposGrupos AS D

ON D.Id = A.IdGrup JOIN centrodb.H_Turno AS E

ON E.Id = A.IdTurn

WHERE E.Turno = 'M' GROUP BY B.NomeColaborador ORDER BY RAND() LIMIT 8
    
05.02.2018 / 12:55