SQL
SQL
SQL can be divided into two parts: The Data Manipulation Language (DML) and the Data
Definition Language (DDL).
RDBMS
SELECT column_name(s)
FROM table_name
ORDER BY column_name(s) ASC|DESC
SELECT column_name(s)
FROM table_name
WHERE column_name operator value
UPDATE Persons
SET Address='Nissestien 67', City='Sandnes'
WHERE LastName='Tjessem' AND FirstName='Jakob'
IN If you know the exact value you want to return for at least one of the columns
LIKE OPERATOR
SELECT column_name
FROM table_name
WHERE column_name LIKE 's%'
SELECT firstname
FROM person.contact
WHERE firstname LIKE 's%'
(Here we select only firstname that starts with s)
Substitutes
% A substitute for zero or more characters
_ A substitute for exactly one character
[charlist] Any single character in charlist
[!charlist] Any single character in charlist here it doesn't start with
Now we want to select the persons with a last name that starts with "b" or "s" or "p" from the
"Person.contact" table.
SELECT * FROM Person.contact
WHERE LastName LIKE '[bsp]%'
Next, we want to select the persons with a last name that do not start with "b" or "s" or "p" from
the "Person.contact" table.
SELECT * FROM Person.contact
WHERE LastName LIKE '[!bsp]%'
BETWEEN OPERATOR
SELECT column_name(s)
FROM table_name
WHERE column_name
BETWEEN value1 AND value2
SELECT *
FROM person.contact
WHERE contactid between 1 and 50
To display the persons outside the range in the previous example, use NOT BETWEEN:
NOT BETWEEN '400' AND '800'
SQL
SELECT TOP number *
FROM table_name
SELECT TOP 2 *
FROM person.contact
MySQL Syntax
SELECT column_name(s)
FROM table_name
LIMIT number
Oracle Syntax
SELECT column_name(s)
FROM table_name
WHERE ROWNUM <= number