May 25, 2025
This project showcases my hands-on SQL practice involving table creation, data insertion, and multiple types of joins and constraints. The goal was to strengthen my understanding of database relationships and advanced SQL queries.
departments: Stores department names.students: Stores student info along withdepartment_idas a foreign key.courses: Stores a list of available course titles.
- Inserted sample data into all three tables (
departments,students,courses).
- Created a foreign key constraint on
students.department_idreferencingdepartments.id. - Practiced:
ON DELETE CASCADE: Automatically deletes students when the department is deleted.ON DELETE SET NULL: Sets student’sdepartment_idto NULL when the department is deleted.
- Filtering recent activity
→ Students who logged in within the last 30 days. - Grouping by login month
→ UsedEXTRACT(MONTH FROM last_login)andGROUP BY. - Aggregate filtering
→ Counted students per month with logins. - INNER JOIN
→ Fetched student names with department names. - LEFT JOIN
→ Showed all students, even those with no department. - RIGHT JOIN
→ Showed all departments, even those with no students. - FULL JOIN
→ Combined all records from both students and departments. - CROSS JOIN
→ Created a Cartesian product of students and courses. - NATURAL JOIN
→ Performed a natural join using a common column (department_id).
- Table creation
- Foreign key constraints
- JOINs:
- INNER JOIN
- LEFT JOIN
- RIGHT JOIN
- FULL JOIN
- NATURAL JOIN
- CROSS JOIN
- Data filtering with
BETWEEN,EXTRACT, andGROUP BY - Aggregate functions (
COUNT) - Column renaming using
ALTER TABLE - Practice subqueries- how subquery works, how retrive data combining two condigion by subquery.
- Learned why
NATURAL JOINmay return no results if multiple columns don’t match by name and values. - Practiced modifying column names to align for natural joins.
- Practice subqueries
- Learn and apply window functions
- Explore indexing and performance optimization
- Create ER diagrams to visualize relationships
Nayem – Junior Full-Stack MERN Developer and passionate learner of SQL