Cheatsheets / Learn SQL
Queries
‘AND Operator
‘The so operator allows multiple conditions to be
combined. Records must match both conditions
joined by sp to be included in the result set. The given
query will match any car that is blue and made after 2014,
at are
AS Clause
Columns or tables can be aliased using
This allows columns or tables to be specifically renamed
in the returned result set. The given query will return 8
result set with the column for nane renamed to
OR Operator
‘The ot operator allows multiple conditions to be
combined. Records matching either condition joined by
the ot are included it
result set, The given query will
match customers whose stale is either ca" or “wv
% Wildcard
‘The % wildcard can be used ina xke operator p
‘to match zero or more unspecified character(s) The given
query will match any movie that begins with the ,
followed by zer0 or more of any characters.
SELECT Statement
‘The sc.ecr + statement returns all columns from the
provided table n the result set. The given query wil fetch
all columns and records (rows) from the sovies table.
_Wildcard
‘The __wildeard can be used ina Uke operator p
to match any single unspecified character. The given
query will match any movie which begins with a single
character, followed by ove
s
FROM
WHERE *blue’
AND year > 2014
ECT
AS ‘movie title’
FROM
SELECT
FROM
WHERE “ca
oR "Ny"
SELECT
ROM
WHERE
“Thex"
SELECT
FROM
LIKE '_oveORDER BY Clause
The ofoek ey clause can be used to sort the result et by
a particular column elther alphabetically or numerically. It
cean be ordered in two ways:
is @ keyword used to sort the results in
descending order.
sc Isa keyword used to sort the results in
ascending order (default
LIKE Operator
The LiKe operator canbe used inside of a were clause
to match a specified pattern. The given query will match
any movie that begins with star inits title
DISTINCT Clause
Unique values of a column can be selected using @
istancr query. For a table contact detatis having ve
rows in which the city column contains Chicago,
Madison, Boston, Madison, and Denver, the given query
would return:
BETWEEN Operator
‘The setveen operator can be used to filter by a range of
values. The range of values can be text, numbers, or date,
data. The given query will match any movie made
between the years 1980 and 1990, inclusive.
LIMIT Clause
The Limrt clause is used to narrow, or limit, a result set
to the specified number of rows. The given query wil mit
the result set to 5 rows,
SELECT
FROM
ORDER BY Desc
SELECT
FROM
WHERE LIKE ‘star%"
SELECT DISTINCT
FROM
SELECT
FROM
WHERE year BETWEEN 1980 AND 1996
SELECT
FROM
LIMIT 5NULL Values
Column values can be wit , or have no value, These
records can be matched (or not matched) using the 15
MLL and 15 nor suLL operators in combination with the
iene clause. The given query will match all addresses
where the address has a value or isnot nut
WHERE Clause
The ese clause is used to fiter records (rows) that
match a certain condition. The given query will select all
records where the pub_year equals 2017
SELECT
FROM
WHERE
SELECT
ROM
WHERE
TS NOT NULL
2017