You can use the SQL Assistant to help you create a query to run with DB2 Web Query
To create a statement using the SQL Assistant:
1. Open the SQL Assistant window. (From the Edit Query Window, click SQL Assist).
2. From the drop-down list, select the type of SQL statement that you want to create. You can create a select statement, a delete statement, or an update statement.
3. Click the Tables button. The Table Selection section appears.
4. In the Creator list, highlight the creator of the table that you want to select from, delete from or update. The tables that are associated with the selected creator, appear in the Tables list.
5. In the Tables list, highlight the table from which you want to select, delete or that you want to update. Click Add. The selected table appears in the Query Workspace.
6. Repeat steps 3-5 for all of the tables that you want to use in your SQL statement.
7. Click Columns. The columns in the selected table or tables appear in the Query Workspace.
8. From the list of columns for each table. Highlight the column or columns that you want to use in your query. Click Add (+). The selected columns appear in the Columns area.
9. In the Columns area, assign the name by which you want to refer to each column in the As field.
10. From the Action list, select the action that you want to perform on that column. You can select:
· None – To have no actions performed on the row
· Sort Ascending – To have the row sorted in ascending order
· Sort Descending - To have the row sorted in descending order
11. Optional: Move a column up or down in the list by checking the Select check box for that column and using the up or down arrows.
12. Optional: in the Columns area, click Add (+) to add a custom column. A column is added to the list. Specify the column name in the Column field. The name by which the column will be called in the query in the As field and the action to be performed on the column in from the Action list. If your custom column calls a function that creates numeric values, you can select the group by radio button to have your results grouped by the custom column.
13. Check the Select check box for each column that you want to use in your SQL statement.
14. Click Conditions. The Row Conditions area appears.
15. In the Query Workspace, highlight the rows to which you want to add row conditions and click the Add (+) icon.
16. In the Row Conditions area, specify the row conditions for each row that you selected using the equation provided. Use the And (&) icon to create an AND condition between two rows, use the OR (|) icon to create an OR row condition between two rows.
Note: You can also use the icons in the Row Conditions area to move row conditions up and down in the list, Add new row conditions, duplicate existing row conditions, and delete existing row conditions.
17. Check the Select check box for each column that you want to use in your SQL statement.
18. Click Joins. The Joins area appears.
19. In the Query Workspace, check the check boxes on the two tables that you want to use in your join.
20. In the Query Workspace, highlight one row in each of the tables that you selected to use in the join.
21. Click the icon corresponding to the type of join that you want to do. You must highlight rows from different tables. The types of joins that are available are:
· Left outer join
· Inner join
· Right outer join
· Full outer join
The join appears in the Joins area.
22. In the Joins area, select the desired join condition from the Condition list.
Note: If you need to switch the order of the joined columns that you have selected, select the join that you need to swap and click the Swap button.
23. Check the Select check box for each join that you want to use in your SQL statement.
24. Click Create query. Your SQL statement is created.