2
I’m trying to create a query to bring results that are in different tables in the Mysql,3 but I’m not getting it.
I have experience in JOIN in the SQL, but I’m picking up a little bit to do in the Mysql, can you help me? I have already consulted here on the site, but I could not solve my problem. I thought about JOIN and subselects to solve my problem.
I would like to relate and bring as a result the following information:
select nome from usuario
select nome from entregadores
select nome from status
I thought about that JOIN here, but you’re wrong.
select d.nome, c.nome, a.km, a.valor, a.valor_extra, a.data, b.nome from
viagens A
inner join b.entregadores
on (a.usuarios_id=d.usuarios_id)
inner join c.status
on (a.entregadores_id=b.entregadores_id)
inner join d.viagens
on (a.status_id=c.status_id)
Follows the structure of my tables:
Travel chart:
viagens_id
usuarios_id
entregadores_id
forma_pagamento_id
status_id
tipo_valor_id
endereco_origem
numero_origem
contato_origem
complemento_origem
ida_volta
data_horario
valor
valor_extra
observacoes
data_criado
data_modificado
user_modificou
distancia
ativo
deleted
Table users:
usuarios_id
grupo_id
empresas_id
nome
login
senha
email
telefone
codigo_seguranca
departamento
thumb
ramal
data_criado
data_modificado
ativo
deleted
Status table:
status_id
nome
ativo
deleted
padrao
Delivery table:
entregadores_id
veiculos_id
nome
cnh
telefone1
telefone2
placa
email
vencimento_cnh
foto_cnh
foto_doc
data_criado
data_modificado
ativo
deleted
It follows my last Query execution with the columns with the right name, presented another error in Phpmyadmin "I had put some columns with wrong name, tidied and I started this way the query select status.name statusName, trips.value
trips, trips.distance, trips.valor_extra,
couriers.name of the couriers
from travel
natural John Couriers
natural Join status
natural Join users
Phpmyadmin brought error "#1267 - Illegal combination of collations (latin1_swedish_ci,IMPLICIT) and (latin1_general_ci,IMPLICIT) to operation '='""
select status.name statuesName, trips.value trips, trips.distance, trips.valor_extra, couriers.name of the couriers from travel natural John Couriers natural Join status natural Join users
You can post the attributes of each table?
– Max Fratane
I edited the post with the structure of my tables, with the name of the columns of each one.
– Mauricio3012