Skip to main content


developerWorks  >  Information Management | XML  >

SQL & XQuery tutorial for IBM DB2, Part 5: Data comparison

Using advanced queries to compare data

developerWorks

Level: Introductory

Pat Moffatt (pmoffatt@ca.ibm.com), Information Management Program Manager, IBM Academic Initiative, IBM 
Bruce Creighton (bcreight@ca.ibm.com), Skills Segment Planner, IBM 
Jessica Cao , Training Tools Developer, IBM 

24 Aug 2006

Register now or sign in using your IBM ID and password.

This tutorial describes queries that compare data in an IBM® DB2® database. This is accomplished by using either CASE expressions or subqueries. This tutorial is Part 5 of the SQL & XQuery tutorial for IBM DB2 series.

Prerequisites

This tutorial was written for DB2 Express-C 9 for UNIX®, Linux® and Windows® (formerly known as Viper). You should be familiar with DB2 and databases. It is preferable that you view tutorials one, two, three, and four in this series before attempting this tutorial, part five.


System requirements

To use this tutorial to the fullest, you should have IBM DB2 9 installed. Download DB2 Express-C, a no-charge version of DB2 Express Edition for the community that offers the same core data features as DB2 Express Edtion and provides a solid base to build and deploy applications. You will also need to install the Aroma database, which can be downloaded in the tutorial.



Duration

Under 2 hours


Formats

html, pdf


About this tutorial

This tutorial discusses queries that compare data in an IBM DB2 database. It begins by illustrating the problem that confronts the query writer: how to use SQL to return a spreadsheet or "cross-tab" report rather than a standard, vertically ordered result set that is hard to read. The problem is solved by using either CASE expressions or subqueries.

The CASE solution, presented first, is a simple and concise way of comparing similar groups of values. Next, several examples of FROM clause and select-list subqueries are presented. These subqueries have the added value of being able to both compare data from different groups and include calculations against the compared values, such as share percentages over given time periods.

This tutorial describes subqueries stated as conditions in the WHERE clause, which are useful for simpler comparison queries. The last section also describes the ALL, EXISTS, and SOME or ANY predicates, which can be used to express conditions on subquery results.

Share this....

digg Digg this story del.icio.us del.icio.us Slashdot Slashdot it!


Back to top


Document options

Document options requiring JavaScript are not displayed

Discuss


More in this series:
SQL & XQuery tutorial for IBM DB2