In Brief
XQuery is a declarative language. After an item is defined within a given scope (such as a program block or function), the item can't be redefined within that scope.
The let statement defines a function that has a constant value.
The for keyword assigns to a temporary variable successive values in a sequence.
The return keyword takes the sets defined by for and let statements and turns them into a resultXML, a sequence of values, a single string expression, and so on.
The where keyword lets you define conditions about which data should be chosen. It creates a predicate cause that narrows a range of potential options.
The order by command follows for expressions (and where expressions where they exist) and indicates for a given set of data the order in which the data is output. When it is not explicitly specified with order by, the output order depends on the system architecture.
XQuery works with XPath's conditional if/then/else keywords to create logical expressions.
XQuery provides many built-in functions and also lets you create user-definable functions. Anything passed into an XQuery function is passed by value, not reference, and a function must always return something of value.