The first step in building a SQL statement is to specify tables and columns in the SELECT/FROM Clause dialog box To complete this dialog box, follow these steps.
This procedure assumes that you have already created a new SELECT statement, as described in Creating a New SQL Statement.
1.Select SQL Statement Ø Tables or the Tables button.
The SELECT/FROM Clause dialog box appears.
1.Select tables and columns for the SELECT statement as described in Selecting Tables and Columns for SELECT UPDATE and INSERT Statements.
2.If you want to eliminate duplicate rows from the Result Set when you run this SELECT statement, check the Distinct Result Set box.
This inserts the keyword DISTINCT into the SELECT statement.
3.If you want to build an expression as part of the SELECT statement, select the Computed Column push button.
The Computed Column dialog box appears. For information about using this dialog box to build an expression, see Adding a Computed Column.
If you checked the Distinct Result Set box as described in Step 3, the DISTINCT key in the keypad of the Computed Column dialog box is disabled. This is because you cannot have both a distinct result set and a distinct computed column in the same SELECT statement.
4.Select the OK push button.
DB/Assist adds the selected tables and columns to the current SELECT statement in the SQL Editor window and to the SAM that contains this statement.
For example, below shows the SELECT/FROM Clause dialog box that builds the following SELECT statement:
SELECT DISTINCT STAFF.ID, STAFF.NAME, STAFF.DEPT FROM DB2ADMIN.STAFF STAFF
Sample SELECT/FROM Clause Dialog Box
If you selected columns from more than one table in the SELECT/FROM Clause dialog box, and a primary/foreign key relationship exists between these tables, DB/Assist enables you to automatically apply a join clause to your SELECT statement. For information about how to do this, see Adding a Join Clause.
Once you build a basic SELECT statement, you can refine it as needed by adding one or more of the following:
•Computed column
•WHERE clause
•Join clause
•ORDER BY clause
•GROUP BY clause
The following sections describe how to build each of these SQL clauses in DB/Assist.