Professional Documents
Culture Documents
SQL Clause What It Does Required
SQL Clause What It Does Required
Like a sentence, a SQL statement has clauses. Each clause performs a function for the SQL statement.
Some clauses are required in a SELECT statement. The following table lists the most common SQL
clauses.
SQL TERMS
Each SQL clause is composed of terms — comparable to parts of speech. The following table lists types
of SQL terms.
Append Statement
INSERT INTO [table_name] ([column1], [column2], [column3])
VALUES ('value1', #value2#, value3);
This assumes value1 is a string, value2 is a date and value 3 is some other datatype
Update Statement
UPDATE [table_name] SET [column_name] = 'value1'
WHERE [other_column]=value2;
Delete Statement
DELETE * FROM [table_name];
Order by is Ascending by default. Use DESC at the of the statement to reverse the order.
IN Value List
SELECT [column_name]
FROM [table_name]
WHERE [column_name] IN ('value1', 'value2', 'value3');
Between Numbers
SELECT [column_name]
FROM [table_name]
WHERE [column_name] BETWEEN value1 AND value2;
Between Dates
SELECT [column_name]
FROM [table_name]
WHERE [column_name] BETWEEN #value1# AND #value2#;
Count
SELECT COUNT([column_name])
FROM [table_name];
However in Aggregate queries if other columns are returned you must use Group By
JOINS
SELECT [Table1].[Column_1], [Table2].[Column_2]
FROM Table1 INNER JOIN Table2
ON [Table1].[ID] = [Table2].[ID];
Union
SELECT [column_name] FROM [table_1]
UNION [ALL]
SELECT [column_name] FROM [table_2];
The ALL predicate is required if you don't want duplicate records to be dropped.
UNION on it's own has the effect of using the DISTINCT predicate in a SELECT clause.