Learn how relational databases store tabular data, how primary/foreign keys enforce integrity, and how to query with SELECT and WHERE.
The Foundations of Relational Databases
Structured Query Language (SQL) is the universal standard for defining, querying, and updating relational database management systems (RDBMS) like PostgreSQL, MySQL, and SQLite.
Core Relational Integrity Rules
Primary Key (PK): Unique non-null identifier for every row in a table.
Foreign Key (FK): References the primary key of another table, ensuring referential integrity.
SQL
-- Filter high-enrollment active courses
SELECT
course_id,
course_name,
category,
enrolled_count
FROM courses
WHERE is_published = 1
AND enrolled_count >= 500
ORDER BY enrolled_count DESC
LIMIT 10;
Connect disparate data tables seamlessly and compute meaningful metrics with aggregate functions and HAVING filters.
Combining Relations with JOIN Operations
In normalized databases, data is split across specialized tables to prevent duplication. JOIN operations allow you to assemble rich composite reports on demand:
SQL
SELECT
u.username,
c.course_name,
e.enrollment_date,
e.completion_percentage
FROM enrollments e
INNER JOIN users u ON e.user_id = u.id
INNER JOIN courses c ON e.course_id = c.id
WHERE e.completion_percentage = 100
ORDER BY e.enrollment_date DESC;
Build an E-Commerce Analytics Query Suite and design a normalized University Schema.
Project 1: E-Commerce Revenue & Retention Query Suite
Intermediate
Write an analytical query suite calculating Monthly Recurring Revenue (MRR), Average Order Value (AOV), and customer churn rates.
Production Blueprint
SELECT
DATE_FORMAT(order_date, '%Y-%m') as sales_month,
COUNT(order_id) as total_orders,
SUM(total_amount) as gross_revenue
FROM orders
GROUP BY sales_month
ORDER BY sales_month DESC;
Project 2: University Course Enrollment Database Schema
Advanced
Design a 3NF relational schema covering students, professors, courses, prerequisites, and grade transcripts with appropriate B-Tree indexing.
Production Blueprint
CREATE TABLE students (
student_id INT AUTO_INCREMENT PRIMARY KEY,
first_name VARCHAR(50) NOT NULL,
email VARCHAR(100) UNIQUE NOT NULL
);