SQL Reference Guide

User Manual:

Open the PDF directly: View PDF PDF.
Page Count: 2

CREATE TABLE cities (
city VARCHAR(30) NOT NULL,
state VARCHAR(30) NOT NULL,
population INT
);
CREATE TABLE cities
city state population
INSERT INTO cities (city,
state, population)
VALUES ('Alameda',
'California', 79177);
INSERT INTO
VALUES
SELECT
SELECT *
FROM cities;
*
FROM
WHERE
// Return rows with a specific
value in column_a
SELECT *
FROM table_1
WHERE column_a = 'value';
WHERE AND
// Include multiple values with
the AND operator
SELECT *
FROM table_1
WHERE column_a = 'value'
AND column_b = 'value';
WHERE OR
// Return data containing
either one value or another
using the OR operator
SELECT *
FROM table_1
WHERE column_a = 'value'
OR column_b = 'value';
WHERE IN
// Return data containing
multiple values in a column
using the IN operator
SELECT *
FROM table_1
WHERE column_a IN ('value_a',
'value_b');
WHERE NOT
// Exclude certain data with
the WHERE NOT operators
SELECT *
FROM table_1
WHERE NOT column_a = 'value';
WHERE NOT IN
// Exclude certain values from
a query using the NOT IN
operators
SELECT *
FROM table_1
WHERE column_a NOT IN
('value_a', 'value_b');
LEFT JOIN
SELECT column(s)
FROM table_1
LEFT JOIN table_2
ON table_1.column_name =
table_2.column_name;
RIGHT JOIN
SELECT column(s)
FROM table_1
RIGHT JOIN table_2
ON table_1.column_name =
table_2.column_name;
INNER JOIN
SELECT column(s)
FROM table_1
INNER JOIN table_2
ON table_1.column_name =
table_2.column_name;
CROSS JOIN
SELECT column(s)
FROM table_1
CROSS JOIN table_2;
FULL OUTER JOIN
OUTER
SELECT column(s)
FROM table_1
FULL OUTER JOIN table_b
ON table_1.column_name =
table_2.column_name;
CREATE TABLE people (
id SERIAL PRIMARY KEY,
name VARCHAR(30) NOT NULL,
has_pet BOOLEAN DEFAULT false,
pet_type VARCHAR(10) NOT NULL,
pet_name VARCHAR(30),
pet_age INT
);
people id
SERIAL PRIMARY KEY, id
SERIAL
PRIMARY KEY
id
LIKE
%
// Substitute zero to multiple characters in a
query
SELECT *
FROM actor
WHERE last_name
LIKE 'Will%';
_
// Substitute a single character in a query
SELECT *
FROM actor
WHERE first_name
LIKE '_AN';

Navigation menu