SQL: Find a usage of all some any to see the effect in SSMs

Source: Internet
Author: User

SET Nocount ON

Use tempdb
Go

IF (object_id (' T1 ') is not NULL)
DROP TABLE T1
CREATE TABLE T1 (n INT)
INSERT into T1
SELECT 2
UNION
SELECT 3

IF (object_id (' T2 ') is not NULL)
DROP TABLE T2
CREATE TABLE T2 (n INT)
INSERT into T2
SELECT 1
UNION
SELECT 2
UNION
SELECT 3
UNION
SELECT 4

--T1 table data 2,3
--T2 table Data 1,2,3,4
SELECT *
from T1
SELECT *
From T2
--' >all ' indicates that the data for column n in the T2 table is greater than the number of columns n in the T1 table, and the result is only 4.
SELECT *
From T2
WHERE n > All (SELECT n
from T1)
--4
SELECT *
From T2
WHERE n > any (SELECT n
from T1)
--3,4
SELECT *
From T2
WHERE n > SOME (SELECT n
from T1)
--3,4

SELECT *
From T2
WHERE n = All (SELECT n
from T1)
--No data
SELECT *
From T2
WHERE n = any (SELECT n
from T1)
--2,3
SELECT *
From T2
WHERE n = SOME (SELECT n
from T1)
--2,3

SELECT *
From T2
WHERE N < All (SELECT n
from T1)
--1
SELECT *
From T2
WHERE N < any (SELECT n
from T1)
--1,2
SELECT *
From T2
WHERE N < SOME (SELECT n
from T1)
--1,2

SELECT *
From T2
WHERE n <>all (SELECT n
from T1)
--1,4
SELECT *
From T2
WHERE n <>any (SELECT n
from T1)
--1,2,3,4
SELECT *
From T2
WHERE n <>some (SELECT n
from T1)
--1,2,3,4
SET Nocount OFF

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.