SQL Flashcards
(29 cards)
Is SQL a case-sensitive language?
No
Every statement must be terminated with:
A semi-colon (;)
How do you add a comment?
Add “–” before
Order of operations?
Parentheses
Multiplication / division
Addition / subtraction
SELECT clause
Returns a result set of records from one or more tables
Most commonly used DML command
SELECT DISTINCT
Removes duplicate values
WHERE clause
Used to filter data
Comparison Operators
> , >=
!=
Logical Operators
Used with WHERE clause
AND (both conditions must be True)
OR (at least one condition must be True)
NOT (to negate a condition)
IN Operator
Returns values in any of specified values
Example:
WHERE state IN (‘VA’, ‘NY’, ‘CA’)
BETWEEN Operator
WHERE points BETWEEN 100 AND 200
Inclusive of the values provided
LIKE Operator
Used in the WHERE clause to search for a specified pattern in a column
WHERE first_name LIKE ‘b%’
WHERE first_name LIKE ‘%b’
WHERE first_name LIKE ‘b___’
First name starts with b and has any number of characters
First name ends with b and has any number of characters
First name starts with b and ends with exactly 3 characters
WHERE first_name REGEXP ‘ey$|on$’
Returns first names that end with EY or ON
WHERE first_name REGEXP ‘^a’
Returns first names that start with ‘a’
WHERE first_name REGEXP ‘^my|se’
Returns first names that start with MY or contain SE
WHERE first_name REGEXP ‘b[ru]’
Returns first names that contain B followed by R or U
IS NULL Operator
Returns records that are null/don’t contain any data
ORDER BY Clause
Sorts values in ascending order by default
DESC at end of ORDER BY clause to specify descending order
LIMIT Clause
Returns only a specified number of values
LIMIT 6, 3
Skips first 6 entries and returns numbers 7, 8, 9
JOIN (INNER JOIN)
Returns all records that have matching values in both tables
LEFT JOIN
Returns all records from the left table, and the matched records from the right table
RIGHT JOIN
Returns all records from the right table, and the matched records from the left table