SQL Flashcards
select data from a database
SELECT
return only distinct (different) values
SELECT DISTINCT column1, column2, …
FROM table_name;
extract only those records that fulfill a specified condition
SELECT column1, column2, …
FROM table_name
WHERE condition;
Text Fields vs. Numeric Fields
SQL requires single quotes around text values
To specify multiple possible values for a column
IN
SELECT * FROM Customers
WHERE City IN (‘Paris’,’London’);
Search for a pattern
LIKE
SELECT * FROM Customers
WHERE City LIKE ‘s%’;
Between a certain range
BETWEEN
SELECT * FROM Products
WHERE Price BETWEEN 50 AND 60;
Not equal
<> or some version !=
operator displays a record if all the conditions separated
AND
SELECT column1, column2, …
FROM table_name
WHERE condition1 AND condition2 AND condition3 …;
operator displays a record if any of the conditions separated
OR
SELECT column1, column2, …
FROM table_name
WHERE condition1 OR condition2 OR condition3 …;
displays a record if the condition(s) is NOT TRUE
NOT
SELECT column1, column2, …
FROM table_name
WHERE NOT condition;
sorts the records in ascending order
ORDER BY ASC
SELECT column1, column2, …
FROM table_name
ORDER BY column1, column2, … ASC
sorts the records in descending order
ORDER BY DESC
SELECT column1, column2, …
FROM table_name
ORDER BY column1, column2, … DESC;
insert new records in a table
INSERT INTO
INSERT INTO table_name (column1, column2, column3, …)
VALUES (value1, value2, value3, …);
a field with no value
NULL