99 item num557 namefleece pullover price2999 the

Info icon This preview shows pages 22–25. Sign up to view the full content.

<item num="443" name="Deluxe Travel Bag" price="39.99"/> <item num="557" name="Fleece Pullover" price="29.99"/> The where clauses use the = operator to determine whether two values are equal If schemas are not used, both values are untyped compared as strings Unless they are cast to numeric types, join does not consider different represen- tations of the same number equal, e.g., 0557 and 557 88 XQuery – Selecting and Joining Using FLWORs – 44
Image of page 22

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

Outer Joins Previous join examples are inner joins : results do not include items without matching products or products without matching items Create a list of products and join it with the price information: Even if there is no price, include the product in the list for $product in doc("catalog.xml")//product return <product number="{$product/number}">{ attribute price {for $price in doc("prices.xml")//prices/priceList/prod where $product/number = $price/@num return $price/price} }</product> Results <product number="557" price="29.99"/> <product number="563" price="69.99"/> <product number="443" price="39.99"/> <product number="784" price=""/> This is known in relational databases as an outer join Product 784 doesn’t have a price in prices.xml price attribute has an empty value 89 XQuery: Contents Introduction to XQuery XQuery Foundations XQuery Expressions Navigating Input Documents Using Paths Adding Elements and Attributes to Results Selecting and Joining Using FLWORs Sorting and Grouping Functions Updates 90 XQuery – Sorting and Grouping – 45 Sorting in XQuery Path expressions return items in document order By default, results of FLWORs are based on the order of sequence of the for clause order by clause is used to sort data in an order other than document order for $item in doc("order.xml")//item order by $item/@num return $item Several ordering specifications can be used: order by $item/@dept, $item/@num Expressions in ordering specifications can only return one value for each item being sorted Unlike SQL, allowed to order by a value that is not returned by the expression: can order by $item/@dept and only return $item/@num in the results Untyped values are treated like strings number function can be used if untyped values must be treated as numeric for sorting purposes: order by number($item/@num) 91 Order Modifiers Several order modifiers can optionally be specified for each ordering specification ascending and descending specify sort direction; default is ascending Order modifiers apply to only one order specification, as in order by $item/@dept, $item/@num descending empty greatest and empty least indicate whether the empty sequence and NaN should be considered a low value or a high value empty greatest : empty sequence is greater than NaN , NaN is greater than all other values empty least : empty sequence is less than NaN , NaN is less than all other values This applies to the empty sequence and NaN only, not to zero-length strings collation , followed by a collation URI in quotes, specifies a collation used to determine the sort order of strings 92 XQuery – Sorting and Grouping – 46
Image of page 23
Empty Order: Example
Image of page 24

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

Image of page 25
This is the end of the preview. Sign up to access the rest of the document.
  • Winter '15
  • MAhmoudali

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern