Question

When someone is calling a function by "SOME" or "ANY" makes me unsure about this.

Can I think about "SOME" as "OneOf" or "OneFrom"? Like an array (table) searching function? If yes, then what's the difference between SOME and IN?

I am total newbie with SQL

Sorry for my bad english, for some reason I think I am little overtired to use it correctly now

Was it helpful?

Solution

Check the following link for some examples that should clarify the difference between them:

http://technet.microsoft.com/en-us/library/ms175064.aspx

IN only tests for equality, while ALL/ANY/SOME can test against any of the comparison operators.

Here is a sample SQL Fiddle.

-- SQL 2012

CREATE TABLE T1 (ID int) ;

INSERT T1 VALUES (1) ;
INSERT T1 VALUES (2) ;
INSERT T1 VALUES (3) ;
INSERT T1 VALUES (4) ;

SELECT CASE WHEN 3 IN (SELECT id FROM t1) THEN 'in true' ELSE 'in false' END
UNION

SELECT CASE WHEN 3 < SOME (SELECT id FROM t1) THEN 'some true' ELSE 'some false' END
UNION

SELECT CASE WHEN 3 < ANY (SELECT id FROM t1) THEN 'any true' ELSE 'any false' END
UNION

SELECT CASE WHEN 3 < ALL (SELECT id FROM t1) THEN 'all true' ELSE 'all false' END;


/* Returns

all false
any true
in true
some true

*/

OTHER TIPS

If any1 else will google that question I will leave the answer

SOME is a synonym for ANY. IN is equivalent to = ANY.

IN compares every row of the right-hand result looking for (and only for) equality

SOME / ANY works in the same way, but you can use a operator like < != etc. to precise the result (true / false / unknown)

also from http://technet.microsoft.com/en-us/library/ms188074.aspx

When SET ANSI_NULLS is ON, an operator that has one or two NULL expressions returns UNKNOWN. When SET ANSI_NULLS is OFF, the same rules apply, except an equals (=) operator returns TRUE if both expressions are NULL. For example, NULL = NULL returns TRUE when SET ANSI_NULLS is OFF.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top