When two sets are given
s1 ={ a,b,c,d} s2={b,c,d,a}
(i.e)
TableA
Item
a
b
c
d
TableB
Item
b
c
d
a
How to write Sql quer
Watch out, I'm gonna use a Cross Join.
Declare @t1 table(val varchar(20))
Declare @t2 table(val varchar(20))
insert into @t1 values ('a')
insert into @t1 values ('b')
insert into @t1 values ('c')
insert into @t1 values ('d')
insert into @t2 values ('c')
insert into @t2 values ('d')
insert into @t2 values ('b')
insert into @t2 values ('a')
select
case when
count(1) =
(((Select count(1) from @t1)
+ (Select count(1) from @t2)) / 2.0)
then 1 else 0 end as SetsMatch from
@t1 t1 cross join @t2 t2
where t1.val = t2.val