{"id":87,"date":"2011-12-21T14:19:27","date_gmt":"2011-12-21T14:19:27","guid":{"rendered":"https:\/\/sqlserverlearner.azurewebsites.net\/2011\/12\/21\/understanding-some-any-all-operators-with-examples\/"},"modified":"2011-12-21T14:19:27","modified_gmt":"2011-12-21T14:19:27","slug":"understanding-some-any-all-operators-with-examples","status":"publish","type":"post","link":"https:\/\/sqlserverlearner.com\/2011\/12\/21\/understanding-some-any-all-operators-with-examples\/","title":{"rendered":"Understanding SOME ANY ALL Operators with examples"},"content":{"rendered":"
These operators involve a query and a Sub Query.
\nQUERY (CONDITION) SOME|ANY|ALL (SUB QUERY)<\/p>\n
CONDITION Above would include the following operators
\n = (or) (or) ! = (or) > (or) > = (or)! > (or) < (or) < = (or) ! <<\/p>\n
SOME Operator:<\/strong> This operator compares the value in the query with the values in the sub query. It returns true if the value condition matches with any of the results in the sub query.<\/em> Example of using some (or) any operator: INSERT INTO @vTable(ID) IF 2 > SOME (SELECT ID FROM @vTable) IF 3 < ANY (SELECT ID FROM @vTable) In the above query 2 greater some of 1,2 and 3. In the next statement 3 is lesser than any of 1,2 and 3. ALL Operator:<\/strong> This operator compares the value in the query with the values in the sub query. It returns true if the condition matches with all of the results in the sub query.<\/em><\/p>\n Example of using ALL operator: INSERT INTO @vTable(ID) IF 4 > ALL (SELECT ID FROM @vTable) IF 3 > ALL (SELECT ID FROM @vTable) In the above query 4 greater than all of 1,2 and 3. In the next statement 3 greater than all of 1,2 and 3. These operators involve a query and a Sub Query. QUERY (CONDITION) SOME|ANY|ALL (SUB QUERY) CONDITION Above would include the following operators = (or) (or) ! = (or) > (or) > = (or)! > (or) < (or) < = (or) ! < SOME Operator: This operator compares the value in the query with the values in…<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[41,3],"tags":[455,456,457,458,459,460,461,462,463],"class_list":["post-87","post","type-post","status-publish","format-standard","hentry","category-sql-server-basics","category-sqlserverpedia-syndication","tag-any-some-all-sql-server-2005-2008","tag-differences-between-some-any-all-operators","tag-example-of-all-operator","tag-example-of-any-operator","tag-example-of-some-operator","tag-understanding-some-any-all-operators-with-examples","tag-what-is-all-operator","tag-what-is-any-operator","tag-what-is-some-operator"],"_links":{"self":[{"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/posts\/87","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/comments?post=87"}],"version-history":[{"count":0,"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/posts\/87\/revisions"}],"wp:attachment":[{"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/media?parent=87"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/categories?post=87"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/tags?post=87"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}
\nANY operator is same as SOME Operator.<\/strong><\/p>\n
\n[sql]
\nDECLARE @vTable TABLE (ID INT)<\/p>\n
\nSELECT 1
\nUNION
\nSELECT 2
\nUNION
\nSELECT 3<\/p>\n
\nPRINT ‘Returned True’
\nELSE
\nPRINT ‘Returned False’<\/p>\n
\nPRINT ‘Returned True’
\nELSE
\nPRINT ‘Returned False’
\n[\/sql]<\/p>\n
\nSo 2 when compared with 1, 2 is greater.
\nHence the result is true.<\/p>\n
\nSo when compared to each of it none of them return true,
\nHence the result is false.<\/p>\n
\n[sql]
\nDECLARE @vTable TABLE (ID INT)<\/p>\n
\nSELECT 1
\nUNION
\nSELECT 2
\nUNION
\nSELECT 3<\/p>\n
\nPRINT ‘Returned True’
\nELSE
\nPRINT ‘Returned False’<\/p>\n
\nPRINT ‘Returned True’
\nELSE
\nPRINT ‘Returned False’
\n[\/sql]<\/p>\n
\nSo 4 when compared with all of 1, 2 and 3 we can find 4 is greater.
\nHence the result is true.<\/p>\n
\nSo when compared to each of it 3 is greater than 1,2 but is lesser than 3.
\nSo 3 is not greater than all of 1,2,3.
\nHence the result is false.<\/p>\n","protected":false},"excerpt":{"rendered":"