Recover customer orders 1. Duplication ERROR

1

My code:

 SELECT   Pedido.NumPedido
    , Pedido.CdCliente
    , Cliente.Nome
    , Produto.CdProduto
    , Produto.Descricao
    , PedidoItem.Quantidade
    , PedidoItem.ValorUnitario
    , PedidoItem.ValorTotalItem

    FROM Cliente

     INNER JOIN   Pedido ON Cliente.CdCliente = Pedido.CdCliente
     INNER JOIN   PedidoItem ON Cliente.CdCliente = PedidoItem.CdCliente
     INNER JOIN   Produto ON PedidoItem.CdProduto = Produto.CdProduto

    WHERE  (PedidoItem.ValorUnitario * PedidoItem.Quantidade = PedidoItem.ValorTotalItem)  
    AND    (Cliente.Nome = 'ELETROMATIC DE GARCA LTDA')
    AND (Pedido.NumPedido = '1')

    ORDER BY ValorTotalItem ASC

However, if I shoot % with% results duplicate.

Ex: OrderOrder 100, 101, 110 = OrderOrder 1 and OrderOrder 106 = OrderOrder

Exiting the code is:

OrderID 100, 101, 110, 106, and OrderID 8 and OrderID 1.

    
asked by anonymous 12.06.2018 / 15:18

1 answer

1

According to the table and the query you showed, the result is apparently not duplicated because: In the WHERE clause, I noticed that in order to obtain orders from the ELETROMATIC DE GARCA LTDA customer you restrict the results to values ValorTotalItem = QuantityUnit * Quantity , this way there may be different orders with the same products that is your case. From what I understand, you restrict to OrderNumber = '1' so the information does not duplicate, but rather displays multiple orders containing the same product. If you do not want to make the distinction by request try using GROUP BY .

    
12.06.2018 / 16:03