Example: XML query with Order-by attributes

Previous Next

Here is an example of an XML query document with several Order-by attributes specified:

    <Table Name="PERSON">
        <Column Name="FAMILY_NAME" Condition="Jo%"
        <Column name="FIRST_NAME"
            Order-by-seqno ="2"/>
        <Column name="ADDRESS" Condition="%STREET%"/>

This results in an XML output document that contains all columns of all records where FAMILY_NAME starts with 'Jo' and ADDRESS contains 'STREET':

    <PERSON ID="377" FAMILY_NAME="Jones" FIRST_NAME="Bill"
        ADDRESS="HIGHSTREET 501"/>
    <PERSON ID="377" FAMILY_NAME="Jones" FIRST_NAME="Patricia"
        ADDRESS="HIGHSTREET 501"/>
    <PERSON ID="312" FAMILY_NAME="Johnson" FIRST_NAME="Ann"
        ADDRESS="ELM STREET 105"/>

The records are sorted in descending order on FAMILY_NAME, and in ascending order on FIRST_NAME, which is only used for the ordering.

This is equivalent to:

FROM      person
WHERE     family_name   LIKE 'Jo%'
AND       address       LIKE '%STREET%'
ORDER BY  family_name   DESC
,         first_name    ASC