This article may contain affiliate links. If you buy some products using those links, I may receive monetary benefits. See affiliate disclosure here
As someone who has already spent some time with PHP-MySQL websites, I know a little bit of SQL - Structured Query Language. If you don't know, it is a language that allows you to interact with relational databases like MariaDB, MySQL, MS SQL, etc.
So, I wanted to dig a little deeper and deepen my knowledge. But where to start, and what all things should I learn. I wanted an idea. So I asked AI to come up with a list of contents sorted from beginner to advanced level.
Then from my part, I made some modifications to that list to come up with the following table of contents.
Table of Contents for Learning SQL (Beginner to Advanced)
SQL comes in different flavours, like MySQL, PostgreSQL, MS SQL, and so on. The syntax between them varies slightly, but the basic concepts remain the same.
I mostly use MariaDB, which is an alternative to MySQL. So most of the things I discuss here and in the upcoming articles will be from a perspective of MariaDB. I hope that won't be much of an issue in learning SQL.
- see also: how to setup mariadb on a linux server
Basics of SQL
- What is a database & types of databases
- Introduction to Relational Databases
- Data Types in SQL
- Types of SQL commands: DDL, DQL, DML, DCL, TCL, Environment
Commands to Get You Started With SQL
mysql
in the command line- Listing databases:
SHOW DATABASES
- Creating a new database:
CREATE DATABASE
- Setup users:
CREATE USER
,DROP USER
,ALTER USER
- Granting and revoking permissions:
GRANT
,REVOKE
- Creating Tables:
CREATE TABLE
- Modifying Tables:
ALTER TABLE
- Dropping Tables and Databases:
DROP TABLE
,DROP DATABASE
- Constraints: Primary Keys, Foreign Keys, Unique, Not Null
Basic SQL Commands
- SQL Basic commands:
SELECT
,FROM
,WHERE
- Sorting Results:
ORDER BY
- Multiple conditions:
AND
,OR
operators - Limiting Results:
LIMIT
orFETCH FIRST
- Inserting Data:
INSERT INTO
- Updating Data:
UPDATE
- Deleting Data:
DELETE
Intermediate SQL Commands
- Joins:
INNER JOIN
,LEFT JOIN
,RIGHT JOIN
,FULL OUTER JOIN
, Self-Joins - Aggregations:
SUM
,AVG
,COUNT
,MIN
,MAX
- Grouping Results:
GROUP BY
- Filtering Groups:
HAVING
- Beginning a transaction:
BEGIN
- Making changes effective:
COMMIT
- Reverting changes:
ROLLBACK
Advanced SQL
- Subqueries: Scalar, Correlated,
EXISTS
, andIN
- Window Functions:
ROW_NUMBER()
,RANK()
,DENSE_RANK()
,NTILE()
- Set Operations:
UNION
,UNION ALL
,INTERSECT
,EXCEPT
- Recursive Queries:
WITH RECURSIVE
- Stored Procedures
- Triggers
- Views
- User-Defined Functions (UDFs)
- Analytic Functions and Advanced Aggregates
- Using
CASE
for Conditional Logic - Pivoting and Un-pivoting Data
- Query Optimization: Understanding Indexes and Query Plans
- Isolation Levels and Locking Mechanisms
- Constructing Dynamic SQL Queries
- Scripting with SQL
- Writing Readable and Maintainable SQL Code
- Debugging and Analyzing Performance
Next Steps
I already know most of the basic and intermediate SQL commands. But advanced features like transactions, stored procedures, etc are a bit alien to me. So I am looking forward to mastering them. Hope I can also record the progress in a YouTube series, which I will update here.