I have this table
CREATE TABLE T
(No1 INT,
No2 INT
)
INSERT INTO T (No1, No2) VALUES (1, 2)
INSERT INTO T (No1, No2) VALUES (2, 1)
INSERT INTO T (No1, No2) VALUES (3, 4)
INSERT INTO T (No1, No2) VALUES (4, 3)
INSERT INTO T (No1, No2) VALUES (5, 6)
INSERT INTO T (No1, No2) VALUES (6, 5)
INSERT INTO T (No1, No2) VALUES (1, 6)
INSERT INTO T (No1, No2) VALUES (6, 1)
No1 No2
1 2
2 1
3 4
4 3
5 6
6 5
1 6
6 1
What I want is to eliminate rows that have the same value but in the other field. For me No1=1 No2=2 and No1=2 No2=1 is the same thing. At the end I want this as result.
No1 No2
1 2
3 4
5 6
1 6
I tried a lot of things and I did a lot of search but I find nothing. The only way I found is with a Cursor. As I play with millions of records, it is very slow. Is there a way to do this with a query?
Thank you.
SQL Fiddle Example