Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Hi all,Suppose A, B are Sets (table):A = {1, 2, 3}B = (1, 2, 3}I want when A = B then Select 1 else Select 0And I know following method:Where Count (A) = Count (B) AND Count (A intersect B) = Count (A)I am looking for others and best methods!
Set NoCount OnDeclare @A Table (i int)Declare @B Table (j int)Insert into @A Values (1)Insert into @A Values (2)Insert into @A Values (3)Insert into @B Values (1)Insert into @B Values (2)Insert into @B Values (3)select case when exists(select *where (select COUNT(*) from( Select * FROM @A INTERSECT Select * FROM @B )d )= (select COUNT(*) from @A) and (select COUNT(*) from @A)=(select COUNT(*) from @B)) then 1 else 0 end
ms65g
Constraint Violating Yak Guru
497 Posts
Posted - 2009-10-04 : 20:13:22
I know another method.Please post other suggestions and solutions
--case when (B-A)=Null And (A-B)=Null then 1 else 0select case when not exists (select * from @A except select * from @B) and not exists (select * from @B except select * from @A) then 1 else 0 end
ms65g
Constraint Violating Yak Guru
497 Posts
Posted - 2009-10-05 : 10:01:51
I am waiting still!Perhaps, semi-join method is best method. But I do not know.
SELECT CASE WHEN EXISTS(SELECT 1FROM (SELECT k=1, * FROM @A) a LEFT OUTER JOIN (SELECT k=1, * FROM @B) b ON a.i=b.jGROUP BY a.kHAVING COUNT(a.i)=(SELECT COUNT(*) FROM @B) AND COUNT(a.i)=COUNT(b.j)) THEN 1 ELSE 0 END
X002548
Not Just a Number
15586 Posts
Posted - 2009-10-05 : 10:44:40
quote:Originally posted by ms65g I am waiting still!