The ANY
, SOME
and ALL
quantifiers
Firebird has two quantifiers that allow you to compare a value to the results of a subselect:
-
ALL
returnstrue
if the comparison is true for every element in the subselect. -
ANY
andSOME
(full synonyms) returntrue
if the comparison is true for at least one element in the subselect.
With ANY
, SOME
and ALL
you provide the comparison operator yourself.This makes it more flexible than IN
, which only supports the (implicit) ‘=
’ operator.On the other hand, ANY
, SOME
and ALL
only accept a subselect as an argument;you can’t provide an explicit list, as with IN
.
Valid operators are =
, !=
, <
, >
, =<
, ⇒
and all their synonyms.You can’t use LIKE
, CONTAINING
, IS DISTINCT FROM
, or any other operators.
Some usage examples:
-
select name, income from blacksmiths where income > any( select income from goldsmiths )
(returns blacksmiths who earn more than at least one goldsmith)
-
select name, town from blacksmiths where town != all( select distinct town from goldsmiths )
(returns blacksmiths who live in a goldsmithless town)
-
if ( GSIncome !> some( select income from blacksmiths ) ) then PoorGoldsmith = 1; else PoorGoldsmith = 0;
(sets PoorGoldsmith to 1 if at least one blacksmith’s income is not less than the value of GSIncome)