-2

Using SQL Server 2014. Taking the following recordset:

enter image description here

I need to find a way to extract the ordOrderNum which is duplicates, with a different DeliveryNum. In this example, orders 93400460 and 93400467 would be extract, because they are duplicates. Order 93408170 is ok. How can I do that??!

thanks for your time and help

GMB
  • 216,147
  • 25
  • 84
  • 135
Dominic
  • 159
  • 1
  • 3
  • 13
  • 1
    Please read [this](https://spaghettidba.com/2015/04/24/how-to-post-a-t-sql-question-on-a-public-forum/) for some tips on improving your question. – HABO Dec 16 '20 at 19:19

2 Answers2

1

You can use group by and having:

select ordOrderNum 
from mytable
group by ordOrderNum
having min(ordDeliveryNum) <> max(ordDeliveryNum)
GMB
  • 216,147
  • 25
  • 84
  • 135
0

Try this:

SELECT 
ORDORDERNUM, ORDLINENUM, 
COUNT(*) FROM TABLE
GROUP BY 
ORDORDERNUM, ORDLINENUM
Having count(*)>1
Thiyagu
  • 1,260
  • 1
  • 5
  • 14