SQL
SQL
SELECT
Used to select data from a database
SYNTAX:
SELECT column FROM Table;
SELECT DISTINCT
Used to select distinctly different data from a database
COUNT DISTINCT
Using distinct with a count function returns the number of different values
in a field.
SELECT COUNT (DISTINCT Column) FROM Table;
In MS Access:
SELECT Count (*) AS newcolumn
FROM (SELECT DISTINCT column FROM Table);
WHERE
Used to filter records that fulfill a specific condition
SYNTAX:
SELECT * FROM table
WHERE condition;
NOTE!!
Single quotes are used for text values
No quotes used for numerical values
ORDER By
Used to sort the result in either ascending or descending order or
alphabetical order.
SYNTAX:
SELECT * FROM Table
ORDER BY Column (DESC optional);
When using both ASC and DESC
SELECT * FROM table
ORDER BY column ASC, Column DESDC;
AND
The ‘WHERE’ clause can contain ‘AND’ operator.
It is used to filter records based on one or more condition
NOT
Used to produce the result in a negative form.
SYNTAX:
SELECT column
FROM Table
WHERE NOT Condition;
INSERT INTO
Used to insert a new record in the table
NULL
Used for a field with no value
Used in the WHERE clause
You can’t use Comparison operators to determine if a field or record is
null.
SYNTAX:
SELECT column
FROM table
WHERE condition IS NULL; OR WHERE condition IS NOT NULL;
UPDATE
Used to modify the existing records in a table
SYNTAX:
UPDATE Table
SET column = ‘value1’, column2 = value2
WHERE condition;
Multiple Records:
UPDATE Table
SET Updated condition
WHERE condition;
DELETE
Used to delete existing records in a table
SYNTAX:
DELETE FROM table
WHERE condition;
SYNTAX:
SELECT TOP NumOfRecords * FROM Customers;
AGGREGATE FUNCTION
Used to perform a calculation on a set of values and return a single value
Often used with the GROUP BY clause of the SELECT statement
GROUP BY splits the result-set into groups of values and the AGGREGATE
FUNCTION can return a single value for each group.
SYNTAX:
SELECT MIN(column)
FROM Table
WHERE condition;
SELECT MAX(column)
FROM Table
WHERE condition;
COUNT