XQuery for the SQL programmer – Introduction
At DataDirect we often get XQuery coding questions from SQL programmers. It can probably be explained by two main reasons. First there are many developers with a SQL background, not surprising they are looking for some analogy with SQL during their first XQuery steps. Second, with DataDirect XQuery you can use XQuery against relational databases, DataDirect XQuery is a natural inroad for SQL programmers into the world of XML and XQuery.As explained last week, we have good experiences teaching XQuery. I thought it would be a good idea to start a series "XQuery for the SQL programmer" - a light introduction to XQuery from a SQL perspective.
This series is not a general introduction to XQuery. We assume you have already some notions of XQuery (or XPath). You can always refresh your XQuery knowledge reading Learn XQuery in 10 Minutes: An XQuery Tutorial.The following essays are available in this series. This list is updated as posts become available, bookmark it if you want to have the update-to-date and complete list at first hand.
USERS

ITEMS

BIDS
As said, this series make extensive use of examples, all the XQuery examples are fully functional and have been tested with DataDirect XQuery.To get started, let’s look at a first but simple SQL query. Get the item numbers of all motorcycle items.
Stay tuned!
This series is not a general introduction to XQuery. We assume you have already some notions of XQuery (or XPath). You can always refresh your XQuery knowledge reading Learn XQuery in 10 Minutes: An XQuery Tutorial.The following essays are available in this series. This list is updated as posts become available, bookmark it if you want to have the update-to-date and complete list at first hand.
- Introduction (this post)
- The Data Model
- Joining Data
- Operators, functions and conditions
- Grouping and aggregation
- Publishing data as XML
- Updating your database
- Using parameters
- Why XQuery?
- And performance?
USERS
ITEMS
BIDS
select ITEMNOOr in XQuery you could write.
from ITEMS
where DESCRIPTION = 'Motorcycle'
for $item in collection("ITEMS")/ITEMS
where $item/DESCRIPTION = "Motorcycle"
return $item/ITEMNOThis is a FLWOR expression, which stands for "for-let-where-orderby-return". I guess you see the analogy with a SQL select statement. Suppose we want to sort the results by item number. In SQL we add an order by clause.select ITEMNOIn XQuery it’s similar to add an order by clause.
from ITEMS
where DESCRIPTION = 'Motorcycle'
order by ITEMNO
for $item in collection("ITEMS")/ITEMS
where $item/DESCRIPTION = "Motorcycle"
order by $item/ITEMNO
return $item/ITEMNOThis was of course not much more than a quick introduction. In our next post we’ll start with the real work, and discuss the Relational and XML data models.Stay tuned!
Labels: relational, SQL, XQuery




