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 ...
Note: I WANT TO GET THE LATEST 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
TABLEMOVEMENT2
PRODUCTS3TABLE
MOVEDPRODUCTSTABLE4
CLIENTSTABLE5