I. Any/some
WHERE expression operator any (subquery)
WHERE expression operator SOME (subquery)
In fact, any and some are equally effective here, the result set of a subquery can only be a field, the left expression uses operator to perform a comparison operation on each row of the result set, and if one of the results is ' true ', the expression result is ' true ' if the result of the comparison is all ' False ' expression result is ' false '.
> Any is larger than a value in the subquery result
< any is less than one of the values in the subquery results
>= any is greater than or equal to a value in the subquery result
<= any is less than or equal to one of the values in the subquery result
= Any equals a value in the subquery result, which is equivalent to the in
! = Any is not equal to one of the values in the subquery result
Example 1. Query the Tbl_insert table, if field A is greater than the value in a row of table Tbl_test field F
Test=#Select * fromTbl_insertwhereA> any(SelectF fromtbl_test); A|B|C---+---+------- 2 | 2 | A 3 | 3 | - 4 | 4 | - 5 | 5 | Wuyi 6 | 6 | 1 6 | 6 | A 6 | 6 | 661 7 | 7 | 3%1 8 | 8 | 3%_1 8 | 8 |3_%_1 7 | 7 |ABC7 | 7 |ABc7 | 7 |ABC ( -Rows
Two. All
WHERE expression operator All (subquery)
In the same subquery, you can still return only one field, and the result of each row of the subquery results in a "true" expression is ' true ', otherwise ' FALSE '.
> All is larger than all values in the subquery results
< All is smaller than all values in the subquery results
>= all is greater than or equal to all values in the subquery result
<= all is less than or equal to all values in subquery results
= all equals all values in the subquery result (unless the subquery results are all equal, so it doesn't really make sense)
! = All is not equal to any one of the values in the subquery result, equal to
Example 1. Querying the largest row of a Tbl_insert table
Test=#Select * fromTbl_insertwhereA=(Select Max(a) fromTbl_insert); A|B|C---+---+------- 8 | 8 | 3%_1 8 | 8 |3_%_1(2rows) Test=#Select * fromTbl_insertwhereA>= All(SelectA fromTbl_insert); A|B|C---+---+------- 8 | 8 | 3%_1 8 | 8 |3_%_1(2Rows
Example 2. Querying the smallest row of a Tbl_insert table
Test=#Select * fromTbl_insertwhereA<= All(SelectA fromTbl_insert); A|B|C---+---+---- 1 | 1 | One(1row) test=#Select * fromTbl_insertwhereA=(Select min(a) fromTbl_insert); A|B|C---+---+---- 1 | 1 | One(1Row
PostgreSQL----Any/some&&all