1
I’m doing a simple select to return a table in Excel, but when I run the command, some rows are being duplicated in the result. Follow the code below:
SELECT
distinct movimentacao.DATA, movimentacao.COD, CADASTRO_MP.DESCRICAO, CADASTRO_MP.GRUPO, CADASTRO_MP.SUBGRUPO, movimentacao.QUANTIDADE, cadastro_mp.UNIDADE, movimentacao.ENTRADA_SAIDA, movimentacao.ALMOXARIFADO, CADASTRO_MP.ULTIMO_PRECO, CADASTRO_MP.ULTIMO_PRECO * movimentacao.QUANTIDADE
FROM movimentacao
LEFT JOIN CADASTRO_MP
ON CADASTRO_MP.COD = MOVIMENTACAO.COD
ORDER BY movimentacao.DATA;
Can anyone tell me what I’m doing wrong?
I already looked at some questions here at stackoverflow but could not solve my problem.
Uses a
GROUP BY
that solves.– Kayo Bruno
Try adding an example of duplicated data. For this to happen, the problem is in the relationship/data of the tables.
– tvdias
How many duplicate COD records do you have in the CADASTRO_MP table?
– Reginaldo Rigo
As you are using the DISTINCT clause there should be duplicate records in the result. You may get the impression that the lines are duplicated but are not. For example. a text field with extra space makes the field different.
– anonimo
DISTINCT does not work when you select more than one column.
– Reginaldo Rigo