Compares a scalar value with a single-column set of values. SOME and ANY are equivalent.
Here is the example:
CREATE TABLE T1 (ID int) ; GO INSERT T1 VALUES (1) ; INSERT T1 VALUES (2) ; INSERT T1 VALUES (3) ; INSERT T1 VALUES (4) ;
it will return "TRUE", because 3 less than some vaules in table.
IF 3 < SOME (SELECT ID FROM T1) PRINT 'TRUE' ELSE PRINT 'FALSE' ;
it will return "FALSE", because 3 no less than all vaules in table.
IF 3 < ALL (SELECT ID FROM T1) PRINT 'TRUE' ELSE PRINT 'FALSE' ;
in some statements
CREATE TABLE #M1(C1 INT) INSERT #M1 SELECT 2 UNION SELECT 3 UNION SELECT 4 CREATE TABLE #M2(C1 INT) INSERT #M2 SELECT 1 UNION SELECT 2 UNION SELECT 5 --意思是 #M1.C1里面的哪些值不等于 #M2.C1全部值里面的一些值,有点绕,比如:#M1.C1里面的 2 不等于 #M2.C1 全部值里面的一些值(比如不等于1和5),所以2会被查询出来 SELECT * FROM #M1 WHERE C1 <> SOME(SELECT C1 FROM #M2) SELECT * FROM #M1 WHERE C1 = SOME(SELECT C1 FROM #M2)
--下面只有2是不等于#M2里面所有值的,其实这里的 "<> all" = "not in"
SELECT * FROM #M1 WHERE C1 <> all(SELECT C1 FROM #M2)
--同理,下面是空 SELECT * FROM #M1 WHERE C1 = all(SELECT C1 FROM #M2)