SQL/MP Query Guide

Retrieving Data: How to Write Queries
HP NonStop SQL/MP Query Guide524488-003
1-4
Selecting Rows
Selecting Rows
Selecting rows in a table is called restriction. Figure 1-2 shows a SELECT statement
that selects specific rows from the EMPLOYEE table and shows the result table. The
SELECT statement uses a WHERE clause and predicates to restrict the number of
rows returned: return only those employees who are in department number 9000.
Organizing Results
A SELECT statement can include one or more of these optional clauses that organize
results:
An ORDER BY clause to list the retrieved rows in a specified order
A DISTINCT clause to eliminate duplicate rows from the result
A GROUP BY clause to identify columns used for grouping
Figure 1-2. Selecting Rows From a Table (Restriction)
Note. When you specify certain options such as ORDER BY, GROUP BY, and DISTINCT,
SQL usually performs a sort or hashing operation. Such queries can require significant
resources. For more information on using these clauses efficiently, see Minimizing Sort Costs
for Ordering and Grouping Operations on page 3-54.
EMPNUM FIRST_NAME LAST_NAME DEPTNUM JOBCODE SALARY
EMPLOYEE
JERRY
•••
JESSICA
ROGER
•••
DINAH
HOWARD
•••
CRINER
•••
GREEN
CLARK
1000
•••
3500
9000
•••
9000
100
•••
300
100
•••
900
13 700 0. 00
•••
39500.00
17 550 0. 00
•••
37000.00
23
•••
568
1
•••
337
004
ROGER
DINAH
GREEN
CLARK
9000
9000
100
90 0
175500.00
37000.00
EMPNUM FIRST_NAME LAST_NAME DEPTNUM JOBCODE SALARY
1
337
SELECT EMPNUM, FIRST_NAME, LAST_NAME, DEPTNUM, JOBCODE, SALARY
FROM EMPLOYEE WHERE DEPTNUM = 9000 ;
VST0102.vsd