Chapter 2: Queries: Selecting Data from a Table  select syntax

Chapter 2: Queries: Selecting Data from a Table

What are queries?

A SQL query requests data from the database and receives the results. This process, also known as data retrieval, is expressed using the select statement. You can use it for selections, which retrieve a subset of the rows in one or more tables, and you can use it for projections, which retrieve a subset of the columns in one or more tables.

A simple example of a select statement is:

select select_list 
from table_list 
where search_conditions 

The select clause specifies the columns you want to retrieve. The from clause specifies the tables to search. The where clause specifies which rows in the tables you want to see. For example, the following select statement finds the first and the last names of writers living in Oakland from the authors table, in the pubs2 database.

select au_fname, au_lname 
from authors 
where city = "Oakland"

Results of this query appear in columnar format:

au_fname        au_lname 
--------------  ----------- 
Marjorie        Green 
Dick            Straight 
Dirk            Stringer 
Stearns         MacFeather 
Livia           Karsen
 
(5 rows affected)




Copyright © 2005. Sybase Inc. All rights reserved. select syntax

View this book as PDF