SQL Tutorial is an quick way to learn the basic elements of SQL language.
The basic SQL commands are: create, alter, drop, insert, update, delete.
Learn how to use DDL (Data Definition Language) commands and DML Statements (Data Manipulation Language).
DDL consists of defining the objects of a database. The objects of the database are: tables, columns, indexes, constraints.
DML represent commands that manipulate the database. The DML commands are: insert, update, delete.
SQL
SQL MIN
SQL MIN
The SQL MIN function returns the minimum value in a select query.
MIN syntax
SELECT MIN(table_column) FROM table_name;
MIN example
Coder books table
ID | Title | Price | Description |
---|---|---|---|
1 | Learn SQL | 20 | Learn SQL language |
2 | Learn MySQL | 22 | Learn MySQL language |
3 | HTML book | 17 | Learn HTML |
4 | Learn PHP | 20 | Introduction to PHP |
5 | Learn PHP | 20 | PHP course |
SELECT MIN(price) FROM coder_books;
Result
17
SELECT price, MIN(price) min_price FROM coder_books GROUP BY price HAVING count(*) > 1;
Result
Price | max_price |
---|---|
20 | 20 |
SQL MAX
SQL MAX
The SQL MAX function returns the maximum value in a select query.
MAX syntax
SELECT MAX(table_column) FROM table_name;
MAX example
Coder books table
ID | Title | Price | Description |
---|---|---|---|
1 | Learn SQL | 20 | Learn SQL language |
2 | Learn MySQL | 22 | Learn MySQL language |
3 | HTML book | 17 | Learn HTML |
4 | Learn PHP | 20 | Introduction to PHP |
5 | Learn PHP | 20 | PHP course |
SELECT MAX(price) FROM coder_books;
Result
22
SELECT price, MAX(price) max_price FROM coder_books GROUP BY price HAVING count(*) > 1;
Result
Price | max_price |
---|---|
20 | 20 |
SQL SUM
SQL SUM
The SQL SUM function returns the sum value of all rows in a select query.
SUM syntax
SELECT SUM(table_column) FROM table_name;
SUM example
Coder books table
ID | Title | Price | Description |
---|---|---|---|
1 | Learn SQL | 20 | Learn SQL language |
2 | Learn MySQL | 22 | Learn MySQL language |
3 | HTML book | 17 | Learn HTML |
4 | Learn PHP | 20 | Introduction to PHP |
5 | Learn PHP | 20 | PHP course |
SELECT SUM(price) FROM coder_books;
Result
99
SELECT price, SUM(price) sum_price FROM coder_books GROUP BY price HAVING count(*) > 1;
Result
Price | sum_price |
---|---|
20 | 60 |
SQL Count
SQL Count
The SQL COUNT function returns the number of the rows in a select query.
COUNT syntax
SELECT COUNT(*) FROM table_name; SELECT COUNT(column_name) FROM table_name;
COUNT example
Coder books table
ID | Title | Price | Description |
---|---|---|---|
1 | Learn SQL | 20 | Learn SQL language |
2 | Learn MySQL | 22 | Learn MySQL language |
3 | HTML book | 17 | Learn HTML |
4 | Learn PHP | 20 | Introduction to PHP |
5 | Learn PHP | 20 | PHP course |
SELECT COUNT(*) FROM coder_books;
Result
5
SELECT COUNT(price) FROM coder_books WHERE price >= 20;
Result
4
SELECT price, COUNT(price) no_count FROM coder_books GROUP BY price HAVING COUNT(*) > 1;
Result
Price | no_count |
---|---|
20 | 3 |