Queries

Select

SELECT col1, col2 FROM tableName;

As

SELECT col1 newName FROM tableName;
# doesnt change the name in the table 

Distinct

SELECT DISTINCT col1 FROM tableName;
# only outputs none duplicate values, i.e. one of each value

Where (filter rows)

SELECT *
FROM tableName
WHERE (col1 > 88) | (col1  < 80);

Having (filter groups)

SELECT * 
FROM tableName
GROUP BY col1
HAVING AVG(col) < col;
# same as where but works with functions, used to filter groups

Like

SELECT *
FROM tableName
WHERE col1 LIKE 'se_en';
# selects all where col1 se_en, _ means any 1 char

LIKE 'A%';
# anything that begins with the letter A

LIKE '%A%';
# anything before or after A

Is NULL

Note: = ≠ cannot find null values

SELECT *
FROM tableName
WHERE imdb_rating IS NOT NULL;
# only gets none null values

SELECT *
FROM tableName
WHERE imdb_rating IS NULL;
# only gets null values

Between

SELECT *
FROM tableName
WHERE col BETWEEN 'A' AND 'F';
# doesnt inclue Z, but will include a col value of == 'F' only not == 'Fac'
# if you want to include F use G

SELECT *
FROM tableName
WHERE col BETWEEN 0 AND 10;
# 10 is included

AND OR

SELECT *
FROM tableName
WHERE col BETWEEN 0 AND 10
AND col1 > 10
OR col2  > 20;

Order by

SELECT *
FROM tableName
WHERE col = 'YO'
ORDER BY col1 DESC;
# DESC = high to low, Z-A

ORDER BY col1 ASC;
# ASC = low to high, A-Z

Limit

SELECT *
FROM tableName
LIMIT 10;
# only shows 10 rows

Case

Note: the , after select

SELECT *,
	CASE
		WHEN col > 10 THEN 'this string is returned'
		WHEN col > 10 THEN 'this string is returned'
		ELSE 'this string is returned'
	END AS 'col name'
FROM tableName;

Unique

SELECT DISTINCT colName
FROM tableName;