we have customers with multiple sub accounts and I'd need to see if these sub accounts had same day shipments (to consolidate these shipments into 1 and save on freight charges).
I have a Shipment table that shows history of all order shipments:
Customer Acct#, Customer Sub Acct#, Customer Sub Acct#, Order shipment date, Order#
I'm trying to write a query to join this table to itself to compare Order shipment date
select * from Shipment S1 inner join Shipment S2
on Customer Acct#.S1=Customer Acct#.S2 --same master Customer acct
and S1.Order shipment date=S2.Order shipment date --same shipment date
and S1.Order#<>S2.Order# -- exclude duplications on Order#
and S1.Customer Sub Acct#<>S2.Customer Sub Acct# -- exclude duplications on Customer Sub Acct# as I need to find shipments from different Customer Sub Acct within one "Master" Customer Acct#.
BUT I'm getting duplicated /triplicated records like reversed info, like this output for a single "Master" Customer Acct#.
S1.Customer Sub Acct# S2.Customer Sub Acct# S1.Order# S2.Order# S1.Order shipment date S2.Order shipment date
123 789 100 200 1/1/2014 1/1/2014
789 123 200 100 1/1/2014 1/1/2014
How to limit the output to 1 top line?