Java Reference
In-Depth Information
This clause lets you retrieve, for example, the records of all customers living in New
York from the Customers Table shown in Table 3-4 .
Table 3-4: The CUSTOMERS Table
FIRST_NAME
MI
LAST_NAME
STREET
CITY
STATE
ZIP
Michael
A
Corleone
123 Pine
New York
NY
10006
Fredo
X
Corleone
17 Main
New York
NY
10007
Sonny
A
Corleone
123 Walnut
Newark
NJ
12346
Francis
X
Corleone
17 Main
New York
NY
10005
Vito
G
Corleone
23 Oak St
Newark
NJ
12345
Tom
B
Hagen
37 Chestnut
Newark
NJ
12345
Kay
K
Adams
109 Maple
Newark
NJ
12345
Francis
F
Coppola
123 Sunset
Hollywood
CA
23456
Mario
S
Puzo
124 Vine
Hollywood
CA
23456
The SQL query you use to retrieve the records of all customers living in New York is
as follows:
SELECT * FROM Customers WHERE City = 'New York';
The result of this query returns all columns from any row with the CITY column
containing "New York." The order in which the columns are returned is the order in
which they are stored in the database; the row order is arbitrary.
To retrieve columns in a specific order, the column names must be specified in the
desired order in your query. For example, to get the data in First_Name, Last_Name
order, issue this query:
SELECT First_Name, Last_Name FROM Customers WHERE Last_Name = 'Corleone';
To get the order reversed, use this query:
SELECT Last_Name, First_Name FROM Customers WHERE Last_Name = 'Corleone';
Note
Unlike rows in a spreadsheet, records in a database table have no implicit
order. Any ordering you need has to be specified explicitly, using the SQL
ORDER BY command.
SQL Operators
Search WWH ::




Custom Search