SQL Flashcards
(19 cards)
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
Test for NULL Values
IS NULL Syntax or IS NOT NULL SELECT column_names FROM table_name WHERE column_name IS NULL;
modify the existing records in a table
UPDATE
UPDATE table_name
SET column1 = value1, column2 = value2, …
WHERE condition;
delete existing records in a table
DELETE
DELETE FROM table_name WHERE condition;
used to specify the number of records to return.
SELECT column_name(s)
FROM table_name
WHERE condition
LIMIT number;