FLWOR


The programming language XQuery defines FLWOR as an expression that supports iteration and binding of variables to intermediate results. FLWOR is an acronym: FOR, LET, WHERE, ORDER BY, RETURN. FLWOR is loosely analogous to SQL's SELECT-FROM-WHERE and can be used to provide join-like functionality to XML documents.

for $d in doc//deptno
let $e := doc//employee
where count >= 10
order by avg descending
return




First column of the XQuery request shows the for, let, where, order by and return keywords of the FLWOR paradigm. In plain English, this could be read as "Get all departments that have more than ten employees, order these departments by decreasing average salary, and return a report of department numbers, head counts and average salary in each big department". The result could look like:


17
25
12500


24
18
11327


3
32
10725

Example using Microsoft SQL Server


DECLARE @xml XML
SET @xml =
'

42
27


a
b

'
SELECT
x.y.query return $s//item_1/text') as i,
x.y.query return $s//item_2/text') as j
FROM @xml.nodes AS x;