Mastering SQL Queries
Structured Query Language (SQL) is the standard language for storing, manipulating, and retrieving data stored in relational database management systems.
Understanding Table Joins:
INNER JOIN: Returns records that have matching values in both tables.LEFT JOIN: Returns all records from the left table, and matched records from the right table.
sql Example
-- Get user enrollment details with course names
SELECT
u.name AS student_name,
c.title AS course_title,
e.enrolled_at,
COUNT(lp.id) AS completed_lessons
FROM enrollments e
JOIN users u ON e.user_id = u.id
JOIN courses c ON e.course_id = c.id
LEFT JOIN lesson_progress lp ON lp.course_id = c.id AND lp.user_id = u.id AND lp.is_completed = 1
WHERE u.role = "student"
GROUP BY e.id;