Stuctured Query Language (SQL)
(1) a software tool for organizing, managing, protecting, and retrieving data stored in a database system
(2) a
... [Show More] command-based language
(3) a freeform language
Non-Procedural Language
a declarative language that specifies the "what" but not the "how"
Procedural Language
an imperative language that specifies an explicit sequence of steps to follow to produce a result
Data Query Language (DQL)
statements that retrieve and analyze data from the database
Data Manipulation Language (DML)
statements that alter data in the database
Data Definition Language (DDL)
statements that create, alter, and drop database objects
Data Control Language (DCL)
statements that manage access to the data and database
SQL/92 or SQL2
first fairly complete, broad, and comprehensive SQL standard
divided into implementation levels:
(1) entry SQL
(2) intermediate SQL
(3) full SQL
SELECT
specifies desired columns and in which order they will appear
limits data horizontally
FROM
tells the SELECT statement where the data can be found
AS
specifies alias column names
" "
preserves case and blank spaces
delimiters for database object names
*
used to retrieve all columns from a given table
ORDER BY
allows data to be retrieved in a specified order
depending on the software the result set may be ordered by columns that have not been selected
ASC
orders data by 1,2,3 or A,B,C
null values are ordered after non-null values
default
DESC
orders data by 3,2,1 or C,B,A
null values are ordered before non-null values
NULLS FIRST or NULLS LAST
indicates how nulls values are to be ordered
WHERE
specifies a search condition
limits data vertically
' '
preserves case and blank spaces
delimiters for string data
needed when comparing:
(1) comparison values against a character data type column
(2) comparison values used against a date/time data type column
WHERE Predicates
(1) comparison
(2) range
(3) membership
(4) pattern match
(5) null
Comparison
compares one value expression against another value expression
=
<> or !=
<
>
<=
>=
Range
tests whether the value of a given value expression falls within a specified range of values
BETWEEN beginning_value AND ending_value
the beginning and ending values are inclusive
you must use the lower value of the range as the beginning value
Membership
tests a value expression against a list of values
IN(comma-separated list of values)
example:
(1) ... IN ('Roma', 'Oxford', 'London')
(2) ... IN (1800, 2400, 2500)
Pattern Match
tests whether a character string value expression matches a specified character string pattern
LIKE
%
_
example:
(1) ... LIKE '_u%' ... Austin or Bull
(2) ... LIKE '%u_' ... Run or Shut
(3) ... LIKE '_u_' ... Run or Sun
(4) ... LIKE '%u%' ... Austin or Shut [Show Less]