SQL Commands Flashcards
What does the “AS” command do?
allows you to rename a column or table
SELECT column_name AS ‘alias’ from table_name;
What does AVG do?
Returns the average of the numeric value SELECT AVG(column_name_ from table_name
What does the BETWEEN command do?
Filters the result between certain range
SELECT column_name from table_name WHERE column_name BETWEEN value_1 and value_2
What does the CASE command do?
If-then logic to create new variables
SELECT column_name, CASE WHEN condition THEN 'Result_1' WHEN condition THEN 'Result_2' ELSE 'Result_3' END FROM table_name
COUNT
Count non-null rows in a column
SELECT COUNT(column_name_ from table_name;
GROUP BY
Aggregate function
Organizes the output into different groups
SELECT column_name
FROM table_name
GROUP BY column_name
HAVING
Is “WHERE” with aggregate functions
SELECT column_name, COUNT()
FROM table_name
GROUP BY column_name
HAVING COUNT() > value;
Website with these commands
https://www.codecademy.com/articles/sql-commands
Inner Join
Combine different rows from different tables if the JOIN condition is true
SELECT column_name
FROM table_name1
JOIN table_2
ON table_1.column_name = table_2.column_name;
IS NULL / IS NOT NULL
Used with WHERE clause to test for empty values
SELECT column_name
FROM table_name
WHERE column_name IS NOT NULL
LIKE
Special operator used with the WHERE caluse to search for a specific pattern in a column
SELECT column_name
FROM table_name
WHERE column_name LIKE %pulse%
LIMIT
Clause that lets you specific the maximum number of rows the result set will have
SELECT column_name
FROM table_name
LIMIT number;
MAX
function that returns the largest value in a column
SELECT MAX(column_name) FROM table_name;
MIN
Function that returns the smallest value in a column
SELECT MIN(column_name) FROM table_name
OR
Operator that filters the results set to only include where where either condition is true
SELECT column_name
FROM table_name
WHERE column_name = value_1
OR column_name2=value_2