Accessing DB2 data

You can retrieve data by using the SQL statement SELECT to specify a result table that can be derived from one or more tables.

In this information, examples of SQL statements illustrate how to code and use each clause of the SELECT statement to query a table. Examples of more advanced queries explain how to fine-tune your queries by using functions and expressions and how to query multiple tables with more complex statements that include unions, joins, and subqueries. The best way to learn SQL is to develop SQL statements like these examples and then execute them dynamically using a tool such as QMF™ for Workstation.

The data that is retrieved through SQL is always in the form of a table. Like the tables from which you retrieve the data, a result table has rows and columns. A program fetches this data one or more rows at a time.

Begin general-use programming interface information.
Example: Consider this SELECT statement:
SELECT LASTNAME, FIRSTNME
  FROM EMP
  WHERE DEPT = 'D11'
  ORDER BY LASTNAME;

This SELECT statement returns the following result table:

LASTNAME     FIRSTNME
========     ========
BROWN        DAVID
LUTZ         JENNIFER
STERN        IRVING
End general-use programming interface information.

Many of the examples in this information are based on the sample tables, which represent sample information about a computer company.