SQL Cheat Sheet
SQL Cheat Sheet
Create Database
SQL Data Types Cheat Sheet
MySQL SELECT statement command
MySQL WHERE clause commands
MySQL Command INSERT INTO Table
MySQL DELETE command
MySQL Update Command
ORDER BY in MySQL: DESC & ASC
command
MySQL GROUP BY and HAVING Clause command
MySQL Wildcards commands
MYSQL Regular Expressions (REGEXP)
Regular expression Metacharacters
SQL Functions commands
MySQL Aggregate function commands
MySQL IS NULL & IS NOT NULL commands
MySQL AUTO_INCREMENT commands
MYSQL – ALTER, DROP, RENAME, MODIFY
MySQL LIMIT & OFFSET
MySQL SubQuery commands
MySQL JOINS commands
MySQL UNION commands
MySQL in Views commands
MySQL Index commands
Command Description
https://www.guru99.com/sql-cheat-sheet.html#2 1/17
10/1/22, 3:33 PM SQL Cheat Sheet with Commands & Description [Sep 2022]
Command Description
CREATE DATABASE IF NOT EXISTS the Latin1 character set uses the
database1 CHARACTER SET latin1 latin1_swedish_ci collation which is the
COLLATE latin1_swedish_ci Swedish case insensitive order.
Command Description
SMALLINT( )
0 to 65535 UNSIGNED.
) 0 to 16777215 UNSIGNED.
INT( )
0 to 4294967295 UNSIGNED.
https://www.guru99.com/sql-cheat-sheet.html#2 2/17
10/1/22, 3:33 PM SQL Cheat Sheet with Commands & Description [Sep 2022]
Command Description
BIGINT( )
0 to 18446744073709551615 UNSIGNED.
Command Description
Command Description
DATE YYYY-MM-DD
https://www.guru99.com/sql-cheat-sheet.html#2 3/17
10/1/22, 3:33 PM SQL Cheat Sheet with Commands & Description [Sep 2022]
Command Description
TIMESTAMP YYYYMMDDHHMMSS
TIME HH:MM:SS
Command Description
ENUM To store text value chosen from a list of predefined text values.
This is also used for storing text values chosen from a list of predefined
SET
text values. It can have multiple values.
Command Description
https://www.guru99.com/sql-cheat-sheet.html#2 4/17
10/1/22, 3:33 PM SQL Cheat Sheet with Commands & Description [Sep 2022]
Command Description
Command Description
SELECT * FROM table1 WHERE t1 WHERE clause combined with – AND LOGICAL
= 2 AND t2 = 2008; Operator
SELECT * FROM table3 WHERE t3 WHERE clause combined with greater than(>) to
> 2000; COMPARISON OPERATORS
SELECT * FROM table1 WHERE WHERE clause combined with Not Equal to
t1<> 1; (<>)COMPARISON OPERATORS
https://www.guru99.com/sql-cheat-sheet.html#2 5/17
10/1/22, 3:33 PM SQL Cheat Sheet with Commands & Description [Sep 2022]
Command Description
INSERT INTO table1 (t1,t2,t3,t4) VALUES (X1,X2,X3,X4); INSERT data into table
Command Description
Example :-
Command Description
Example :-
https://www.guru99.com/sql-cheat-sheet.html#2 6/17
10/1/22, 3:33 PM SQL Cheat Sheet with Commands & Description [Sep 2022]
Command Description
Order by
SELECT statement… [WHERE condition | GROUP BY field_name(s)
clause basic
HAVING condition] ORDER BY field_name(s) [ASC | DESC];
syntax
Example :-
Group by
Command Description
SELECT t4 FROM table1 GROUP BY t4;( suppose we want to get the unique values for t4.)
https://www.guru99.com/sql-cheat-sheet.html#2 7/17
10/1/22, 3:33 PM SQL Cheat Sheet with Commands & Description [Sep 2022]
Command Description
HAVING clause
Command Description
SELECT * FROM table2 GROUP BY all the t4 for table2 t1 id x1. We would use the
t1_id,t4 HAVING t1_id = x1; following script to achieve our results.
Command Description
Example :- we would use the percentage wildcard to perform a pattern match on both
sides of the word “X1” as part t2 of table1
Learn Java
Programming with
Beginners Tutorial
08:32
What is Integration
Testing Software Testing
https://www.guru99.com/sql-cheat-sheet.html#2 8/17
10/1/22, 3:33 PM SQL Cheat Sheet with Commands & Description [Sep 2022]
Command Description
SELECT * FROM table1 WHERE t3 LIKE all the table1 that were t3 in the year
x2_; “x2”
Command Description
SELECT * FROM table1 WHERE t3 Suppose we want to get table1 that were not t3
NOT LIKE X2_; in the year X2_
Command Description
Command Description
Example :- all the table1 t1 that have the word X1 in them. It does not matter whether
the “X1” is at the beginning, middle or end of the title.
https://www.guru99.com/sql-cheat-sheet.html#2 9/17
10/1/22, 3:33 PM SQL Cheat Sheet with Commands & Description [Sep 2022]
Command Description
[abc] The charlist [abc] is used to match any of the enclosed characters.
String functions
Command Description
SELECT t1_id,t2,
the “UCASE” function to do that. It takes a string as a
UCASE(t2) FROM
parameter and converts all the letters to upper case.
table1;
Numeric functions
/ Division SELECT 23 / 6 ;
- Subtraction SELECT 23 – 6 ;
+ Addition SELECT 23 + 6 ;
SELECT 23 * 6 AS
* Multiplication
multiplication_result;
% or SELECT 23 % 6 ; or
Modulus
MOD SELECT 23 MOD 6;
Stored functions
Command Description
https://www.guru99.com/sql-cheat-sheet.html#2 11/17
10/1/22, 3:33 PM SQL Cheat Sheet with Commands & Description [Sep 2022]
Command Description
CREATE FUNCTION
sf_name
([parameter(s)])
DETERMINISTIC
STATEMENTS
CREATE FUNCTION Mandatory and tells MySQL server to create a function named
sf_name `sf_name’ with optional parameters defined in the
([parameter(s)]) parenthesis.
Command Description
https://www.guru99.com/sql-cheat-sheet.html#2 12/17
10/1/22, 3:33 PM SQL Cheat Sheet with Commands & Description [Sep 2022]
Command Description
Null as a Value
( if t3 have null value present that not count)
t2_names varchar(255) ,
NOT NULL Values
t3 varchar(6)
);
comlumn_name IS NULL
NULL Keywords Basic
comlumn_name NOT NULL syntax
Command Description
);
Command Description
https://www.guru99.com/sql-cheat-sheet.html#2 13/17
10/1/22, 3:33 PM SQL Cheat Sheet with Commands & Description [Sep 2022]
Command Description
RENAME COMMAND
RENAME TABLE current_table_name TO new_table_name;
syntax
ALTER TABLE table1 ADD t4 date NULL AFTER t3; AFTER KEYWORD
Command Description
Command Description
Command Description
https://www.guru99.com/sql-cheat-sheet.html#2 14/17
10/1/22, 3:33 PM SQL Cheat Sheet with Commands & Description [Sep 2022]
Command Description
FROM table2 AS A
LEFT JOIN
LEFT JOIN table1 AS B
ON B.table2_id = A.id
FROM table1 AS A
RIGHT JOIN
RIGHT JOIN table2 AS B
ON B.id = A.table2_id
FROM table2 AS A
USING ( table2_id )
Command Description
Command Description
https://www.guru99.com/sql-cheat-sheet.html#2 15/17
10/1/22, 3:33 PM SQL Cheat Sheet with Commands & Description [Sep 2022]
Command Description
About
About Us
Advertise with Us
Write For Us
Contact Us
Career Suggestion
SAP Career Suggestion Tool
Interesting
eBook
Blog
Quiz
https://www.guru99.com/sql-cheat-sheet.html#2 16/17
10/1/22, 3:33 PM SQL Cheat Sheet with Commands & Description [Sep 2022]
Q
SAP eBook
Execute online
Execute Javascript
Execute HTML
Execute Python
https://www.guru99.com/sql-cheat-sheet.html#2 17/17