9.1. Querying DB2 Data

You use the SELECT statement to query tables or views from a database. At a minimum, the statement contains a SELECT clause and a FROM clause. The following are two examples of a SELECT statement. This first example uses the wildcard symbol (*) to indicate that all columns from the employee table are selected:

					SELECT * FROM employee;
				

In this example, the column names are specified in the SELECT statement:

					SELECT empno, firstnme, lastname FROM employee;
				

9.1.1. Derived Columns

When data is retrieved from a table using the SELECT clause, you can derive new columns based on other columns. Figure 9.1 illustrates this: the column totalpay is derived by adding the salary and comm columns.

Figure 9.1. Example of a derived column ...

Get Understanding DB2®: Learning Visually with Examples now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.