I have two tables wherein one of the columns contain the data which is comma separated. I need to compare both the columns. The comma separated fields can be in any order, but the order is irrelevant.
create table x_a (id1 integer, shared text);
create table x_b (id1 integer, shared text);
insert into x_a values
(1, 'A,B,C,D,E')
, (2, 'A,B,C,D,E');
insert into x_b values
(1, 'B,A,C,E,D')
, (2, 'B,A,C,E');
I used below query, but it is not returning any output:
select a.id1,b.id1, a.shared, b.shared
from x_a a ,x_b b
where a.id1 = b.id1
and regexp_split_to_array(LOWER(a.shared),',')
= regexp_split_to_array(LOWER(b.shared),',')
I cannot use the operator &&
as it will return id=2
which is wrong as the "Shared" column is not the exact copy.