SQL - Group information and Do not repeat

Asked

Viewed 54 times

1

I’m doing an SQL where I need to show the purchase orders. However a purchase order, can have several quotations and do not want to keep repeating the quotations, I want to bring me the quotation only once without repeating.

[![select c.Empresa, p.Nome, 
c.data,c.NumeroOC, c.fornecedor, pe.nome, 
(Convert(Numeric(10,2), c.valor)) as 'Valor',
det.descricao as 'Local de Entrega',l.Descricao as 'CR',
Case when c.situacao = 1 then
    'Pendente'
    when c.situacao = 2 then
    'Atendida Parcialmente'
    when c.situacao = 3 then
    'Atendida Totalmente'
    when c.situacao = 4 then
    'Finalizada Manualmente' end as 'Status',
c.ordemaut, 
ic.Cotacao,
c.Obs
from compras c
inner join pessoas p on (c.empresa = p.codigo)
inner join pessoas pe on (c.fornecedor = pe.codigo)
inner join locais l on (c.cresultado = l.codigo) and tipolocal = 'CR'
inner join detpessoas det on (det.Sequencial = c.LocalEntrega)
inner join itenscompra ic on (c.SequencialOC = ic.SequencialOC)][1]][1]
  • 1

    And which of the existing quotes would you like to see displayed? I believe that the GROUP BY clause and an aggregation function (MAX for example) can help you.

  • I just don’t want to see it repeated. If a PURCHASE ORDER has had 2 quotes, I want to see the Dudas, but I don’t want to see them repeated.

  • 1

    Define better what you mean by "repetitions" since, from what I understand, you want to see such repetitions.

  • I posted a photo too. The oc number and the quotations are the same and I want to group them. I even tried to make a group by, but the bank asks me to group field by field, which is unfeasible in the query.

  • 1

    Attached images are not welcome on this site. See: Manual on how NOT to ask questions

1 answer

1

if I understand the question

try using "select distinct c.Company, p.Name, c.data,c.Numerooc, c.fornecedor, pe.nome from

avoids repetitions.

  • Solved! Thank you very much!

  • If you do INNER JOIN of a set of tables and the data comes repeated then most likely your database has serious design problems.

Browser other questions tagged

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