0
I am trying to make a query in the MYSQL database, but the query is not getting back what I wanted. I want to make a query where return all modules and modules that the company has with the clause where
in Empresa_ID
.
Mysql attempt:
SELECT empresas.empresa_id
,empresas.empresa_razaosocial
,modulos.modulo_id
,modulos.modulo_nome
,empresa_modulo.modulo_id
FROM empresa_modulo
RIGHT JOIN modulos
ON modulos.modulo_id = empresa_modulo.modulo_id
RIGHT JOIN empresas
ON empresas.empresa_id = empresa_modulo.empresa_id
UNION
SELECT empresas.empresa_id
,empresas.empresa_razaosocial
,modulos.modulo_id
,modulos.modulo_nome
,empresa_modulo.modulo_id
FROM empresa_modulo
RIGHT JOIN modulos
ON modulos.modulo_id = empresa_modulo.modulo_id
RIGHT JOIN empresas
ON empresa_modulo.empresa_id = empresas.empresa_id
WHERE empresas.empresa_id = 1;
Upshot:
I did this consultation, but I was not successful. How can I perform this consultation?
A query that returns all the modules and modules that the company has.
Without having an example of the data it is difficult to help. Apparently your query is right, it cannot be data that was not found in
right join
?– Ricardo Pontual
What do you want? What comes back? Explain better.
– Mauro Alexandre
It’s right, right, right
– Joan Marcos
@Joanmarcos You need to show a sample of the data, what you’re getting at the moment, and what you’d like to receive when it’s right.
– user94991
@user94991 is the result.
– Joan Marcos