SQL Cheatsheet
SQL Cheatsheet
Select queries
CHAR
String (0 - 255)
VARCHAR
String (0 - 255)
TINYTEXT
String (0 - 255)
TEXT
String (0 - 65535)
BLOB
String (0 - 65535)
MEDIUMTEXT
String (0 - 16777215)
MEDIUMBLOB
String (0 - 16777215)
LONGTEXT
String (0 - 4294967295)
LONGBLOB
String (0 - 4294967295)
SMALLINT x
MEDIUMINT x
Integer (-8388608 to
8388607)
GROUP BY col1;
BIGINT x
group results
Integer (-
create a database
FLOAT
DOUBLE
DECIMAL
DATE
YYYY-MM-DD
YYYY-MM-DD HH:MM:SS
TIMESTAMP
YYYYMMDDHHMMSS
TIME
HH:MM:SS
ENUM
SET
2147483647)
9223372036854775807)
DATETIME
DESC];
Integer (-2147483648 to
9223372036854775808 to
condition;
TINYINT x
INT x
INNER
JOIN
tables
OUTER
JOIN
LEFT
JOIN
RIGHT
JOIN
in right table
JOIN syntax:
SELECT * FROM tbl1 INNER JOIN tbl2 ON
tbl1.id = tbl2.id;
STRCMP("str1","str2")
Convert to lower
LOWER("str")
case
Convert to upper
UPPER("str")
case
Left trim
LTRIM("str")
Substring of a
SUBSTRING("str","inx1","i
string
nx2")
Concatenate
CONCAT("str1","str2")
By guslong
Sponsored by Readability-Score.com
cheatography.com/guslong/
Page 1 of 2.
https://readability-score.com
COUNT(col)
Average
AVG(col)
Minimum value
MIN(col)
Maximum value
MAX(col)
Sum of values
SUM(col)
By guslong
Sponsored by Readability-Score.com
cheatography.com/guslong/
Page 2 of 2.
https://readability-score.com