A comprehensive SQL practice environment with sample databases and progressive exercises.
- Sample Databases: Realistic datasets to practice with
- Progressive Exercises: From basic SELECT to advanced JOINs and subqueries
- Solutions: Step-by-step explanations for each exercise
- Quick Reference: Essential SQL syntax and commands
-
Install SQLite (if not already installed):
# Ubuntu/Debian sudo apt install sqlite3 # macOS brew install sqlite # Windows - download from https://sqlite.org/download.html
-
Create the sample database (choose one method):
Method A - Using Python (recommended):
python3 setup/create_database.py
Method B - Using SQL script:
# Remove existing database first (if any) rm -f company.db # Create fresh database sqlite3 company.db < setup/create_database.sql
-
Start practicing:
sqlite3 company.db
- employees: Employee information (id, name, department, salary, hire_date)
- departments: Department details (id, name, manager_id, budget)
- projects: Project information (id, name, department_id, budget, start_date, end_date)
- employee_projects: Many-to-many relationship between employees and projects
- Basic SELECT statements
- WHERE clauses and filtering
- Sorting with ORDER BY
- Basic aggregate functions (COUNT, SUM, AVG)
- JOINs (INNER, LEFT, RIGHT)
- GROUP BY and HAVING
- Subqueries
- Date/time functions
- Complex JOINs with multiple tables
- Window functions
- Common Table Expressions (CTEs)
- Performance optimization
- Read the exercise description in each
.mdfile - Try writing your SQL query
- Test it in SQLite:
sqlite3 company.db - Check your answer against the solution
- Read the explanation to understand the concepts
# Enter SQLite CLI
sqlite3 company.db
# Show all tables
.tables
# Show table structure
.schema employees
# Run a SQL file
.read exercises/01_beginner/exercise_01.sql
# Exit SQLite
.quit- Start small: Begin with simple SELECT statements
- Practice regularly: SQL is best learned through hands-on practice
- Understand the data: Always explore your tables first with
SELECT * FROM table LIMIT 5 - Read error messages: SQLite gives helpful error messages
- Experiment: Try variations of queries to see what happens
- SQLite Documentation
- SQL Tutorial
- SQLite Browser - GUI tool for exploring databases
Happy learning! 🚀