0

I've checked everywhere for a simple solution to this and I can not find it. Say you have a database

column A column B
function A function B
function B function A
function C function D
function D function C
function E function F
function H function G

I want to get rid of the combination of unique values, so I output this

column A column B
function A function B
function C function D
function E function F
function H function G

Is there an elegant way to achieve this?

3
  • Is it possible to have unique combinations as well (ex: ColA = 'Fct 3' / ColB = 'Fct 17')? Are the combination always the same, I mean: could 'function 1' be associated to 'function 20' as well? Commented Sep 16, 2021 at 14:04
  • Just trying to understand the requirement here - is it the case that you want combination of values from the columns whereas in your source table you have permutation of values? Commented Sep 16, 2021 at 14:59
  • Yes, any permutation of values in columns that are not distinct should be discarded Commented Sep 16, 2021 at 15:28

1 Answer 1

2

You can use <:

select t.*
from t
where column_a < column_b;

This will select one row from each reversed pair, the one where column_a has the lower value.

EDIT:

The question changed after I answered it. That is pretty rude, but I'll adjust the answer anyway:

select t.*
from t
where column_a < column_b or 
      not exists (select 1
                  from t t2
                  where t2.column_a = t.column_b and
                        t2.column_b = t.column_a
                 );
Sign up to request clarification or add additional context in comments.

3 Comments

What if instead of function 1 we have function A, function B, etc?
Also updated my question to include other non combination rows
@gordon-linoff : will this solution work if the example table's 1st or 3rd row are not present.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.