A structured, beginner-friendly collection of SQL exercises and practice problems designed to help you master Structured Query Language — from basic queries to advanced topics like window functions, CTEs, and query optimization.
sql-practice/
│
├── README.md # You are here
├── .gitignore # Ignored files for SQL projects
├── schema.sql # Database schema (Employee & Department tables)
├── sample_data.sql # Realistic sample data for practice
├── progress.md # Track your learning progress
│
├── basics/ # Fundamental SQL queries
│ ├── select.sql
│ ├── where.sql
│ ├── order_by.sql
│ ├── limit.sql
│ └── distinct.sql
│
├── filtering/ # Filtering techniques
│ ├── like.sql
│ ├── between.sql
│ ├── in.sql
│ └── null.sql
│
├── sorting-grouping/ # Sorting and aggregation
│ ├── group_by.sql
│ ├── having.sql
│ └── aggregate_functions.sql
│
├── joins/ # Joining tables
│ ├── inner_join.sql
│ ├── left_join.sql
│ ├── right_join.sql
│ ├── full_join.sql
│ └── self_join.sql
│
├── advanced/ # Advanced SQL concepts
│ ├── subqueries.sql
│ ├── cte.sql
│ ├── window_functions.sql
│ ├── case.sql
│ └── views.sql
│
├── interview_questions/ # Practice interview-style SQL problems
└── notes/ # Your personal SQL notes
To run these SQL files, you'll need one of the following:
- MySQL (version 8.0+ recommended)
- PostgreSQL (version 12+ recommended)
- SQLite (for lightweight practice)
- Any SQL database of your choice
- MySQL Workbench – GUI for MySQL
- pgAdmin – GUI for PostgreSQL
- DBeaver – Universal database tool
- VS Code with SQL extensions (like SQLite Viewer or MySQL)
git clone https://github.com/your-username/sql-practice.git
cd sql-practiceRun the schema file to create the tables:
MySQL / PostgreSQL:
source schema.sql;SQLite:
sqlite3 practice.db < schema.sqlsource sample_data.sql;Open any .sql file in your preferred SQL editor and start writing your queries in the placeholder sections provided.
-- Example: Run a SELECT query
SELECT * FROM Employee;
SELECT * FROM Department;| Topic | Files |
|---|---|
| Basics | SELECT, WHERE, ORDER BY, LIMIT, DISTINCT |
| Filtering | LIKE, BETWEEN, IN, NULL handling |
| Sorting & Grouping | GROUP BY, HAVING, Aggregate Functions |
| Joins | INNER JOIN, LEFT JOIN, RIGHT JOIN, FULL JOIN, SELF JOIN |
| Advanced | Subqueries, CTEs, Window Functions, CASE, Views |
The repository includes two primary tables:
| Column | Type | Description |
|---|---|---|
| emp_id | INT (PK) | Unique employee ID |
| emp_name | VARCHAR | Employee full name |
| job_title | VARCHAR | Job position |
| manager_id | INT (FK) | Reports to (self-referencing) |
| date_hired | DATE | Hire date |
| salary | DECIMAL | Monthly salary |
| dept_id | INT (FK) | Department ID |
| Column | Type | Description |
|---|---|---|
| dept_id | INT (PK) | Unique department ID |
| dept_name | VARCHAR | Department name |
| location | VARCHAR | Office location |
Use progress.md to track which topics you've completed and add notes about what you've learned.
This is a personal practice repository, but feel free to fork it and adapt it for your own learning journey!
This project is for educational purposes. Feel free to use and modify it.