Inner Join returning empty

Asked

Viewed 398 times

0

I have a SELECT to return a list of products, but I want them to be differentiated by input and output, contains and does not contain...

Obs: I WANT TO TAKE THE LAST MOVEMENT OF EACH PRODUCT

Select that I have so far

SELECT DISTINCT * 
FROM EstoqueGeral e
LEFT OUTER JOIN (

SELECT  * 
FROM produto_movimento 
GROUP BY codigoproduto
) AS mvp ON mvp.codigoproduto = e.codigo2

LEFT OUTER JOIN (
SELECT DISTINCT * 
FROM estoque_movimentacao
GROUP BY idmov
) AS em ON mvp.idmov = em.idmov

LEFT OUTER JOIN (

SELECT DISTINCT * 
FROM clientes2
GROUP BY ID_cliente
) AS c ON c.cpf = em.cliente

ORDER BY `mvp`.`id_pm`  DESC
LIMIT 15

RETURN

RETORNO

MOVING TABLE 2

TABELA MOVIMENTACAO

TABLE OF PRODUCTS 3

TABELA PRODUTOS

TABLE PRODUCTS MOVED 4

TABELA PRODUTOS MOVIMENTADO

SCHEDULE 5

TABELA CLIENTES

  • you have some error like return or unwanted data ?

  • it does not return error, it simply does not return the other tables

1 answer

0

should not be appearing because the INNER JOIN switches to LEFT JOIN so to see if it returns or tries it more will get heavy or something like that

 SELECT * FROM EstoqueGeral e
    LEFT JOIN produto_movimento mvp 
        ON 
            mvp.codigoproduto = e.codigo2 AND 
            mvp.codigoproduto  = ( SELECT mvp2.codigoproduto FROM produto_movimento ORDER BY mvp2.codigoproduto DESC LIMIT 1 )
  • Now returns null

  • This query is not joining the client table as I do to get, just follow this logic?

  • yes adds other left

Browser other questions tagged

You are not signed in. Login or sign up in order to post.