Record Selection

The most basic SQL statements are constructed through selection statements. Selection statements return a group of records whose values can be filtered, grouped, ordered, or altered. To jump into the basics of SQL, you must first learn how to create a simple selection query.

Selection Statements

Statements that select records all begin with the keyword SELECT. The syntax for a simple select statement is as follows:

SELECT [predicate] {* |
                    field_name1 [AS alias_name1]
                    [field_name2 [AS alias_name2]] [, ...]]}
FROM table_expression
 [IN external_database]

This syntax declaration might be slightly intimidating if you have never seen SQL before, but rest assured, you will know this like the back of your hand before long.

Let’s begin by taking a look at the simplest of all select statements, one without any predicate (or secondary keyword), the SELECT statement.

SELECT

The SELECT statement is used to return selected fields from all records, in one or more tables, located in the current database or an external database. Let’s image that we have a table named Employees in our current database. The Employees table has the following field names: FirstName, LastName, and EmployeeID. The Employees table is populated as in Table A-1.

Table A-1. The Employees Table

FirstName

LastName

EmployeeID

Jason

Roff

100

Tammi

Roff

101

Kimberly

Roff

102

John

DelWhatta

200

John

Katsosing

201

By using a simple SELECT statement, we can list all of the employees and their IDs:

SELECT ...

Get ADO: ActiveX Data Objects now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.