Use the GREATEST () and LEAST () functions to identify common values ββfor multiple columns. Then use DISTINCT to display duplicates.
select distinct least(a, b) as a , greatest(a, b) as b , c from t6
This gives you the exact set of records you requested. But things get complicated if you need to include other columns from T6.
"But I was wondering if this would work for VARCHAR2 fields as well?"
Yes, but it will use ASCII values ββto determine order, which does not always mean what you can expect (or desire).
"In addition, my T6 table can have tens of thousands of records."
It really is not much data under today's conditions. DISTINCT will cause a sort that should be able to fit in memory if A
and B
are not really long VARCHAR2 columns, but maybe even then.
If this is a query that you want to run a lot, you can create an index based on functions to satisfy it:
create index t6_fbi on t6(least(a, b) , greatest(a, b) , c ) /
But I would really worry if you have a performance issue with the query.
APC
source share