Microsoft Office Tutorials and References
In Depth Information
The SELECT Statement
You’ll notice that SQL statements such as SELECT and INSERT are shown in
upper case. This is a standard SQL programming practice and a good habit
to get into from the start. The SQL code examples you’ll see in this topic are
relatively small, but SQL code can be very large and complex. SQL is easier to
read when its statements are shown in upper case, distinguishing them from the
clauses of code with which they are associated.
The sElEcT statement
The SELECT statement retrieves data in the form of one or more rows (records) from one or more
tables. The SELECT statement is probably SQL’s most commonly used operation, because it tells the
data source what field(s) you want to return from what table(s).
If you want to retrieve all columns and all rows from the Vendors table, the expression in SQL
would be as follows:
FROM Vendors
Sometimes you might not want to retrieve all columns. The following example will retrieve the State
column from the Vendors table, if you want to know the count of your vendors per state.
FROM Vendors
If you want to see a list of vendors and the names of their contact people, but only for vendors
in California, the following example would accomplish that. Note that the literal string criterion
California is in single quotes, which is SQL’s required syntax.
SELECT VendorName, ContactName
FROM Vendors
WHERE State ‘California’
If you want to retrieve the previous recordset by having it already sorted by the VendorName field,
you could add the ORDER BY statement and specify the field name as follows:
SELECT VendorName, ContactName
FROM Vendors
WHERE State ‘California’
ORDER BY VendorName
Search JabSto ::

Custom Search