SELECT column_name [, ...] FROM table_name
Selects field values from a table.
Example: SELECT FirstName, LastName FROM tblPerson
SELECT DISTINCT column_name FROM table_name
Selects field values and removes duplicates.
Example: SELECT DISTINCT StateCode FROM tblCity
SELECT column_name FROM table_name WHERE condition
Selects field values that match certain criteria. 'Condition' is a comparison, typically including fields, operators, value, and operators being =, !=, <, <=, >, >=, LIKE
Example: SELECT CityName FROM tblCity WHERE StateCode = 'CA'
SELECT column_name FROM table_name WHERE simple-condition {[AND | OR] simple-condition ...}
Selects field values that match multiple criteria.
Example-1: SELECT CityName FROM tblCity WHERE StateCode = 'CA' OR StateCode='FL'
Example-2: SELECT CityName FROM tblCity WHERE CityName = 'Salem' AND StateCode = 'MA'
SELECT column_name FROM table_name WHERE column_name IN ('value1', 'value2', ...)
Selects field values that match a specified set of choices.
Example: SELECT CityName FROM tblCity WHERE StateCode IN ('CA', 'AZ', 'NV')
SELECT column_name FROM table_name WHERE column_name BETWEEN 'value1' AND 'value2'
Note that the quotes around the values apply to text; use the proper delimiters based on the field's data type
Selects field values that are in a certain range.
Example: SELECT CityName FROM tblCity WHERE Population BETWEEN 50000 AND 500000
SELECT column_name FROM table_name WHERE column_name LIKE pattern
Selects field values that contain a certain pattern, such as 'Q%' to start with Q, '%Q' to end with Q, '%Q%' to contain Q, or 'A_BCD' to have anything in the 2nd position.
Note that for Microsoft Access, the match-pattern is an asterisk (*) for "all" and question mark (?) for "any", whereas for standard SQL, those are "%" and "_"
Example: SELECT StateCode FROM tblState WHERE StateCode LIKE 'M%'
SELECT column_name FROM table_name [WHERE condition] ORDER BY column_name [ASC | DESC] [column_name2 [ASC | DESC], ...]
Selects and sorts field values (optionally matching certain criteria.)
Example: SELECT CityName, StateCode FROM tblCity ORDER BY StateCode DESC, CityName
SELECT column_name1, SUM(column_name2) FROM table_name GROUP BY column_name1 [, ...]
Selects field values and groups them together through a function-merge of the data.
Example: SELECT CityName, StateCode FROM tblCity GROUP BY StateCode, CityName
SELECT column_name1, SUM(column_name2) FROM table_name GROUP BY column_name1 HAVING (arithmetic-function-condition)
Selects field values matching certain criteria and groups them together.
Example: SELECT CityName, StateCode FROM tblCity GROUP BY StateCode, CityName HAVING StateCode = 'CA'
SELECT table_alias.column_name1 AS column_alias FROM table_name [AS] table_alias
Selects field values using an alternate name for a column name and table.
Example: SELECT FirstName AS FName, LastName AS LName FROM tblPerson P
SELECT G.region_name AS REGION, SUM(SI.Sales) AS SALES FROM Geography G, Store_Information SI WHERE G.store_name = SI.store_name GROUP BY G.region_name
Selects field values from multiple tables (similar to JOIN.)
Example: SELECT C.CityName, S.StateName FROM tblCity C, tblState S WHERE C.StateCode = S.StateCode
SELECT column_name1 FROM table_name WHERE column_name2 Comparison-Operator (SELECT column_name1 FROM table_name WHERE Condition)
Selects field values where matching criteria comes from another SELECT statement.
Example: SELECT CityName FROM tblCity WHERE StateCode = (SELECT StateCode FROM tblState WHERE StateName = 'Oregon')
SELECT [COUNT | AVG | SUM | MAX | MIN | ...](column_name) FROM table_name
Selects field values and performs a function on them.
Example-1: SELECT COUNT(*) FROM tblCity WHERE StateCode = 'CA'
Example-2: SELECT MAX(Population) FROM tblCity
INSERT INTO table_name [(column_for_text, column_for_number, ...)] [VALUE | VALUES] ('value1', value2, ...)
Example: INSERT INTO tblPerson (FirstName, LastName, PetCount) VALUES ('Chris', 'Horsly', 2)
or
INSERT INTO table_name [(column_for_text, column_for_number, ...)] SELECT ('value1', value2, ...)
Inserts data into the specified fields of a table.
Example: INSERT INTO tblPerson (FirstName, LastName, PetCount) SELECT FName, LName, Pets FROM tblPetsLastYear
UPDATE table_name [as tn1 inner join tbl_name2 as tn2 on tn1.key=tn2.key ...]
SET column1 = 'new-value'[, column2 = 'new_value', ...]
[WHERE condition]
Note: the new-value qualifiers will depend on the data type
Updates data in the specified fields of a table.
Example: UPDATE tblPerson SET LastName = 'Horsely', PetCount = 3 WHERE LastName = 'Horsly'
DELETE [field list] FROM table_name
[WHERE condition]
Note: omitting the WHERE condition will remove all records, but slower than DROP table
Deletes data from a table that matches certain criteria.
Example: DELETE * FROM tblPerson WHERE LastName = 'Horsely'
CREATE TABLE table_name (column1 data_type_for_column_1, column 2 data_type_for_column_2, ... )
Creates a new table with specified columns and data types.
Example: CREATE TABLE tblPets (PetID Integer, PetName Text(20))
DROP TABLE table_name
Deletes a table.
Example: DROP TABLE tblPets
TRUNCATE TABLE table_name
Clears the data from a table (same as "DELETE FROM table" but faster.)
Example: TRUNCATE TABLE tblPetsLastYear2