Datasheet

24
Chapter 1
Introducing SQL
from a single table or from multiple tables. Queries using multiple tables are discussed in
later chapters.
Using the SELECT Statement
The SELECT statement is the most commonly used statement in SQL. It allows you to retrieve
information already stored in the database. The statement begins with the keyword
SELECT,
followed by the column names whose data you want to query. You can select information
either from all the columns (denoted by
*) or from name-specic columns in the SELECT clause
to retrieve data. The
FROM clause provides the name of the table, view, or materialized view
to use in the query. These objects are discussed in detail in later chapters. For simplicity, I
will use tables for the rest of this chapter.
Lets use the
JOBS table dened in the HR schema of the Oracle 11g sample database. You
can use SQL*Plus tool to connect to the database as discussed earlier in the chapter. The
JOBS table denition is provided in Table 1.6.
TABLE 1.6 JOBS Table Definition
Column Name Datatype Length
JOB_ID VARCHAR2 10
JOB_TITLE VARCHAR2 35
MIN_SALARY NUMBER 6,0
MAX_SALARY NUMBER 6,0
The simple form of a SELECT statement to retrieve all the columns and rows from the
JOBS table is as follows (only part of output result set is shown here):
SQL> SELECT * FROM jobs;
JOB_ID JOB_TITLE MIN_SALARY MAX_SALARY
---------- ------------------------------- ---------- ----------
AD_PRES President 20000 40000
AD_VP Administration Vice President 15000 30000
AD_ASST Administration Assistant 3000 6000
FI_MGR Finance Manager 8200 16000
FI_ACCOUNT Accountant 4200 9000
… … … … …
IT_PROG Programmer 4000 10000
95127c01.indd 24 2/18/09 6:37:09 AM