How to pair distinct values from same column on MySQL

I have a table, it has a code and a value, in one select statement (no cursors, temp tables) I need to select the list of pairings as (CODE1, CODE2) from the code column without repeating again with (CODE2, CODE1) Ex.

CODE1, CODE2
CODE1, CODE3
CODE1, CODE4
CODE2, CODE1 <---Value Repeated before as CODE1, CODE2
CODE2, CODE3
CODE2, CODE4
....

Help please.
aisinfoAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Roger BaklundCommented:
The question is confusing, you talk about a code and a value, but the result seems too contain the code twice? Can you show your current query?
0
SharathData EngineerCommented:
This query will give you all records except the below.
CODE1, CODE2
CODE2, CODE1

I am still looking to get one record from the above two records..

SELECT DISTINCT A.Col1,A.Col2
  FROM YourTable A
  JOIN YourTable B
    ON A.Col1 <> B.Col2
   AND A.Col2 <> B.Col1

Open in new window

0
aisinfoAuthor Commented:
Yes, it's supposed to be code twice, it's pairing the codes on that column.
0
Roger BaklundCommented:
I understand that you need the code twice, but it is not clear what you are trying to achieve. What is the criteria in the WHERE clause? Are you using a self join? Are you trying to find duplicates?

I guess you are using a self join to find duplicates, and the where clause contains A.value=B.value and A.code!=B.code?

Try changing A.code!=B.code to A.code<B.code:
select A.code,B.code
from MyTable A, MyTable B
where 
  A.value = B.value and
  A.code < B.code

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
aisinfoAuthor Commented:
So simple, All I was missing was the <. Thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Query Syntax

From novice to tech pro — start learning today.