Question about query mysql

0

I performed a Query on the MySql database, but realized that it brought duplicate values. I did not understand at what point in the Query the problem might be, follow the query.

select  usuarios.nome as usuario,forma_pagamento.nome as forma, status.nome as statu, viagens.valor 
as viagemValor,  viagens.distancia as km, viagens.valor_extra as extra, viagens.data_criado as dtcriado,
entregadores.nome as entregadorNome
from viagens 
inner join entregadores
on (viagens.entregadores_id= entregadores.entregadores_id)
inner join usuarios
on (viagens.usuarios_id= usuarios.usuarios_id)
inner join forma_pagamento
on (viagens.forma_pagamento_id=forma_pagamento.forma_pagamento_id)
inner join status
on (viagens.status_id=status.status_id)
where empresas_id= 11 and viagens.deleted = 0
and viagens.data_criado > '2018-03'
    
asked by anonymous 23.03.2018 / 02:11

1 answer

0

Actually there is no problem in the query, so that the data is not duplicated it is necessary to add distinct to select . I am trying to create a table with the following code:

select distinct
    usuarios.nome as usuario,
    forma_pagamento.nome as forma, 
    status.nome as statu, 
    viagens.valor as viagemValor,  
    viagens.distancia as km, 
    viagens.valor_extra as extra, 
    viagens.data_criado as dtcriado,
    entregadores.nome as entregadorNome
from viagens  
inner join entregadores on (viagens.entregadores_id= entregadores.entregadores_id)
inner join usuarios on (viagens.usuarios_id= usuarios.usuarios_id)
inner join forma_pagamento on (viagens.forma_pagamento_id=forma_pagamento.forma_pagamento_id)
inner join status on (viagens.status_id=status.status_id)
where empresas_id= 11 
    and viagens.deleted = 0
    and viagens.data_criado > '2018-03'
    
23.03.2018 / 02:29