Essential Queries Guide
Learn how to perform essential SQL operations such as creating tables, inserting data, and using aggregate functions like MAX, MIN, and AVG.
Creating a Table
CREATE TABLE t1 ( a INT );CREATE TABLE t2 ( b INT );CREATE TABLE student_tests (
name CHAR(10), test CHAR(10),
score TINYINT, test_date DATE
);Inserting Records
INSERT INTO t1 VALUES (1), (2), (3);INSERT INTO t2 VALUES (2), (4);INSERT INTO student_tests
(name, test, score, test_date) VALUES
('Chun', 'SQL', 75, '2012-11-05'),
('Chun', 'Tuning', 73, '2013-06-14'),
('Esben', 'SQL', 43, '2014-02-11'),
('Esben', 'Tuning', 31, '2014-02-09'),
('Kaolin', 'SQL', 56, '2014-01-01'),
('Kaolin', 'Tuning', 88, '2013-12-29'),
('Tatiana', 'SQL', 87, '2012-04-28'),
('Tatiana', 'Tuning', 83, '2013-09-30');Using AUTO_INCREMENT
Querying from two tables on a common value (JOIN)
Finding the Maximum Value
Finding the Minimum Value
Finding the Average Value
Finding the Maximum Value and Grouping the Results
Ordering Results
Finding the Row with the Minimum of a Particular Column
Finding Rows with the Maximum Value of a Column by Group
Calculating Age
Using User-defined Variables
View Tables in Order of Size
Removing Duplicates
Last updated
Was this helpful?

