One of the most frequently used SQL statements is the SELECT
statement, which extracts specified columns from one or more database tables to build a recordset. Heres the basic syntax for a SELECT
statement:
SELECTColumnName
FROMTableName
You can add line breaks, tabs, and other white space to your statements to clarify the logic: SQL ignores all white space. The following example shows a valid statement:
SELECT PaidDues FROM Members
The following keywords identify commonly used SQL commands:
Keyword |
Description |
---|---|
SELECT |
Retrieves the specified records from a database |
INSERT |
Adds a new record in a database table |
UPDATE |
Changes values in specified database records |
DELETE |
Removes specified database records |
The following keywords are used to refine SQL statements:
Keyword |
Description |
---|---|
FROM |
Names the data source for an operation |
WHERE |
Sets one or more conditions for the operation |
ORDER BY |
Sorts the recordset rows in a specified order |
GROUP BY |
Groups the recordset by the specified select list items |
The following operators specify conditions and perform logical and numeric functions:
Operator |
Meaning |
---|---|
|
Equal to |
|
Like (wildcards OK) |
|
Not equal to |
|
Not like (wildcards OK) |
|
Less than |
|
Greater than |
|
Less than or equal to |
|
Greater than or equal to |
AND |
Both conditions must be met, such as Louisiana AND Texas |
OR |
At least one condition must be met, such as Smith OR Smyth |
NOT |
Exclude the condition following, such as Paris NOT France |
If the item being compared is text, place it in single quotes as in the following example:
...WHERE Country = 'Germany'
If the item being compared is a date and youre working with a Microsoft Access database, enclose it with # signs:
...WHERE DateOfBirth < #01/01/1970#
Other databases may have their own date conventions. Consult the database systems documentation.
Some database systems may use non-standard SQL syntax in their products. Check your database systems documentation.