FILTER statement can be used to restrict the results to elements that match an arbitrary logical condition.
The general syntax for
expression must be a condition that evaluates to either false or true. If the condition result is false, the current element is skipped, so it will not be processed further and not be part of the result. If the condition is true, the current element is not skipped and can be further processed. See
Operators for a list of comparison operators, logical operators etc. that you can use in conditions.
It is allowed to specify multiple
FILTER statements in a query, even in the same block. If multiple
FILTER statements are used, their results will be combined with a logical
AND, meaning all filter conditions must be true to include an element.
Note that the positions of
FILTER statements can influence the result of a query. There are 250 countries in the test data for instance:
We can limit the result set to 5 countries at most:
This may return strings Argentina, Anguilla, Armenia, Antarctica, American Samoa. Which ones are returned is undefined, since there is no SORT statement to ensure a particular order. If we add a second FILTER statement to only return women…