Microsoft Office Tutorials and References
In Depth Information
SQL and Recordsets
As a language, SQL can get fairly complex. The syntax of a basic SQL
statement looks something like this:
SELECT fields1 FROM table(s) [WHERE criterion ] [ORDER BY fields2 ]
fields1 represents a list of fields from the table (or * for all fields);
table(s) represents the name of the table (or tables) where the data are
stored; criterion represents an expression that filters records (such as
State=”CA”); and fields2 represents fields to use for sorting the records.
The WHERE and ORDER BY portions are optional.
Writing SQL statements
Writing SQL statements is fairly easy after a bit of practice. Don’t worry —
you rarely need to write them by hand. Every time you create a query
by using Design view, you actually write a SQL statement. The fields that
you choose for the query are the fields that get included in the recordset,
although only those fields that have a check mark in the Show check box are
actually included. The FROM table, from which you select records, is plainly
visible at the top of the grid. The Sort row defines the ORDER BY clause. The
Criteria row specifies the WHERE clause, as illustrated in Figure 5-3.
Figure 5-3:
Every query
contains
components
of a SQL
query.
To see the SQL statement for any query you create, right-click the title bar
or document tab of your query (in Design view), and choose the SQL View
option from the contextual menu. Alternatively, click Results on the (Query
Tools) Design tab of the Ribbon, and choose View SQL View. You see the
SQL statement that the query uses to get the data specified, as shown in
Figure 5-4. The SQL statement may already be selected (highlighted); copy it
to the clipboard, if you want, by pressing Ctrl+C.
Search JabSto ::




Custom Search