all, any, some查询

use E_Market
go
--[1]>all父查询的列的值必须大于子查询返回的值列表中的每一个值
select * from table2 where n > all ( select n from table1)

--返回结果为4
--table2(1,2,3,4)
--table1(2,3)

--[2]>any 父查询的列中的值至少大于子查询返回值列表中的一个值
select * from table2 where n > any ( select n from table1)

--结果为3和4

--[3]改为some的形式,some和any的功能一样
select * from table2 where n > some ( select n from table1)

--结果为3和4

--【4】=any与子查询中的in是等效的,父查询中列的值,必须在子查询返回的列表中存在
select * from table2 where n = any ( select n from table1)
select * from table2 where n in ( select n from table1)

--结果均为2,3

--【5】<>any与not in
select * from table2 where n <> any ( select n from table1)
select * from table2 where n not in ( select n from table1)

--<>any:结果为1,2,3,4
--not in:结果为1,4

--<>any:父查询的结果中列的值与子查询返回的值列表中的一个不相同就可以
--not in:父查询的结果中列的值必须不能存在在子查询返回值的列表中

posted @ 2019-05-13 22:47  我是神奇的小白  阅读(192)  评论(0编辑  收藏  举报