?
Solved

Distinct But Reversed Pairs

Posted on 2009-07-15
4
Medium Priority
?
469 Views
Last Modified: 2012-05-07
I have a table similar to:

colA     colB  colC colD
3          11      ...     ...
54        22
11        3
22        11
22        54

I need only distinct pairs, regardless of the order of the elements of a pair.  That is 3, 11 is a duplicate of 11,3.  I need only one of the two rows. Can be either one.  So the above table should be:

colA     colB
3          11
54        22
22        11

0
Comment
Question by:studioEtc
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 60

Expert Comment

by:chapmandew
ID: 24860047
so, you only care about the values in columna and columnb?
0
 
LVL 37

Expert Comment

by:momi_sabag
ID: 24860061
select distinct cola,colb
from yourTable t1
where not exists (select 1 from yourtable t2 where t1.cola = t2.cola and t1.colb = t2.colb and cola>colb)
0
 

Author Comment

by:studioEtc
ID: 24860566
I didn't think I had any problem with other columns but unfortunately I do.  When there are duplicates, I need to retain the row with the highest value in colC.
0
 
LVL 37

Accepted Solution

by:
momi_sabag earned 2000 total points
ID: 24873121
try this

select cola, colb, max(colc)
from  (select case when cola <= colb then cola else colb end as cola,
    case when cola <= colb then colb else cola end as colb, colc
    from yourTable ) t1
group by cola,colb
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
I have a large data set and a SSIS package. How can I load this file in multi threading?
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question