Create Table with Reverse Duplicate Data
CREATE TABLE GETREVERSEDUPLICATE
(COL1 VARCHAR(10),COL2 VARCHAR(10) ,COL3 INT)
INSERT INTO GETREVERSEDUPLICATE
SELECT 'A','B',10
UNION
SELECT 'C','D',20
UNION
SELECT 'B','A',10
UNION
SELECT 'D','C',20
SELECT * FROM GETREVERSEDUPLICATE
OUTPUT:
COL1 COL2 COL3
A B 10
B A 10
C D 20
D C 20
GET REVERSE DUPLICATE WITH EXPECTED OUTPUT
EXPECTED RESULT:
COL1 COL2 COL3
B A 10
D C 20
Query:
SELECT * FROM GETREVERSEDUPLICATE T
WHERE Col1 > Col2
AND EXISTS (
SELECT *
FROM GETREVERSEDUPLICATE AS T1
WHERE T1.Col1 = T.Col2
AND T1.Col2 = T.Col1
);
OUTPUT:
COL1 COL2 COL3
B A 10
D C 20
Please try in Test environment only.
No comments :
Post a Comment