This repository documents my day-wise MySQL learning journey, starting from basic SQL concepts and gradually moving towards advanced database features through hands-on practice in MySQL Workbench.
The goal of this repository is to build a strong foundation in SQL and relational databases by practicing real queries every day.
Understanding basic database operations and writing the first SQL queries confidently.
- What is a database
- Difference between database and table
- How MySQL stores data in tabular format
- CREATE DATABASE
- USE database
- SHOW DATABASES
- CREATE TABLE
- Understanding columns and data types
- DESC table_name
- SHOW TABLES
- INSERT INTO
- SELECT *
- SELECT column_name
- WHERE
- LIMIT
- WHERE clause
- AND / OR conditions
- ORDER BY (ASC, DESC)
- DISTINCT
- LIMIT
- Filtering records using conditions
- Sorting query results
- Fetching unique values
- Limiting output rows
- COUNT
- SUM
- AVG
- MIN
- MAX
- GROUP BY
- Calculated total students
- Found average, minimum, and maximum marks
- Performed department-wise analysis
- Advanced filtering using WHERE
- Sorting results using ORDER BY
- Limiting records using LIMIT
- Removing duplicate values using DISTINCT
- Writing combined conditional queries
- students
- LIKE (pattern matching)
- IN
- NOT IN
- BETWEEN
- Pattern based queries
- Filtering multiple values
- Excluding specific records
- Range based filtering
- Real-world student queries
- INNER JOIN
- Table aliases
- Joining multiple tables
- Created departments table
- Joined students and departments tables
- Retrieved combined information from multiple tables
- Applied filtering on joined data
- LEFT JOIN
- NULL values in joins
- Retrieved all records from the left table
- Identified missing relationships
- Practiced real interview-style join queries
- GROUP BY with aggregate functions
- HAVING clause
- Department-wise student count
- Average and maximum marks by department
- Filtering grouped results using HAVING
- Subqueries
- Single row subqueries
- Subqueries with AVG and MAX
- Correlated subqueries
- Found students scoring above overall average
- Identified student(s) with highest marks
- Found department with highest average marks
- Students scoring above their department average
- Department(s) having maximum number of students
- PRIMARY KEY
- FOREIGN KEY
- UNIQUE
- NOT NULL
- CHECK
- Created departments table with PRIMARY and UNIQUE constraints
- Created students table with NOT NULL and CHECK constraints
- Linked tables using FOREIGN KEY
- Inserted valid data respecting constraints
- Understood parent–child table relationship
- What is a JOIN in SQL
- Why JOIN is required in relational databases
- How tables are linked using PRIMARY KEY and FOREIGN KEY
- How INNER JOIN returns only matching records
- Joined students and departments tables
- Retrieved student details with department names
- Applied WHERE conditions on joined data
- Calculated department-wise student count and average marks
- RIGHT JOIN returns all records from the right table
- NULL values appear when no matching record exists
- MySQL does not support FULL JOIN directly
- FULL JOIN can be simulated using LEFT JOIN + UNION + RIGHT JOIN
- students
- departments
- RIGHT JOIN between students and departments
- Finding departments with no students
- Simulating FULL OUTER JOIN using UNION
- Learned how to handle missing relationships
- Improved JOIN logic for interview questions
- Strengthened relational database understanding
- What is a VIEW and why it is used
- Creating and using views
- Updating data through views
- What is an INDEX
- How indexes improve query performance
- Created views for student and department data
- Retrieved data using views instead of complex queries
- Created indexes on frequently searched columns
- Understood basic performance optimization
- Verified parent table (departments) data
- Inserted records into child table (students)
- Fixed foreign key issues by ensuring correct table mapping
- Retrieved student records successfully
Parent table must contain referenced values before inserting into child table.
- ON DELETE CASCADE removes dependent records automatically
- ON UPDATE CASCADE updates foreign key values automatically
- Maintains consistency between related tables
- Created parent and child tables
- Inserted sample data
- Tested DELETE and UPDATE operations
- Observed automatic changes in related records
- NOT NULL ensures mandatory fields
- UNIQUE prevents duplicate values
- CHECK validates data range
- DEFAULT assigns automatic values
- Created tables using multiple constraints
- Inserted valid records
- Tested constraint failures for invalid data
- Understood how databases enforce rules internally
- What is a View in SQL
- Why Views are used
- How Views store SELECT queries
- How Views behave like tables
- Created a View using JOIN
- Retrieved data from the View
- Applied filtering on the View
- Listed all Views in the database
Views help write clean, reusable, and secure SQL queries.
- What is an Index
- Why Index is used
- How Index improves SELECT query performance
- How to create and inspect Indexes
- Created an Index on student_name
- Executed queries before and after Index
- Viewed existing Indexes on the table
Indexes make searching faster but require extra memory.
- START TRANSACTION begins a transaction
- COMMIT saves changes permanently
- ROLLBACK cancels changes
- SAVEPOINT allows partial rollback
- Updated records inside transactions
- Used ROLLBACK to undo changes
- Used COMMIT to save changes
- Practiced transaction safety concepts
- What is a Stored Procedure
- How procedures store reusable SQL logic
- Using input parameters in procedures
- Created procedure to retrieve all students
- Created procedure to retrieve students above certain marks
- Called procedures using CALL statement
- Viewed procedures using SHOW PROCEDURE STATUS
- What is a Trigger
- How triggers automatically execute on table events
- Difference between BEFORE and AFTER triggers
- Created a log table
- Created an AFTER INSERT trigger
- Automatically stored inserted student names in the log table
- Verified trigger execution using SELECT query
Triggers help automate actions in databases and are commonly used for logging, auditing, and enforcing business rules.
This 21-day MySQL practice journey helped me build a strong foundation in:
- SQL Queries
- Relational Database Design
- Data Integrity
- Performance Optimization
- Database Automation
Through consistent daily practice, I improved my understanding of real-world database concepts and interview-relevant SQL topics.
Today I practiced CASE statements in MySQL, which allow conditional logic inside SQL queries.
- How CASE works in SQL
- Using CASE for conditional categorization
- Applying conditions based on marks
- Combining CASE with ORDER BY
- Categorized students based on marks
- Created performance labels such as Excellent, Good, Average
- Used CASE inside SELECT queries
- Sorted categorized data
- students
CASE statements allow SQL queries to apply conditional logic similar to if-else statements in programming.
Today I practiced Window Functions in MySQL, specifically the ROW_NUMBER() function.
- What are Window Functions
- How ROW_NUMBER() assigns ranking
- Difference between normal ranking and partition ranking
- Using ORDER BY inside window functions
- Ranked students based on marks
- Created department-wise ranking using PARTITION BY
- Observed how ranking resets for each department
- students
Window functions allow calculations across rows related to the current row without grouping the results.
Today I practiced SQL Ranking Functions in MySQL.
- What is RANK() function
- What is DENSE_RANK() function
- Difference between RANK and DENSE_RANK
- Department-wise ranking using PARTITION BY
- Ranked students based on marks
- Compared RANK and DENSE_RANK results
- Applied ranking inside departments
- students
Ranking functions help analyze ordered data and are widely used in analytics and interview SQL questions.
Today I practiced LEAD() and LAG() window functions in MySQL.
- What is LAG() function
- What is LEAD() function
- How to access previous and next row values
- Using PARTITION BY with window functions
- Compared student marks with previous records
- Retrieved next row values using LEAD
- Performed department-wise comparison
- students
LEAD and LAG functions help analyze sequential data by accessing values from previous or next rows.
Today I practiced Common Table Expressions (CTE) in MySQL.
- What is a CTE
- How CTE creates temporary result sets
- How CTE improves query readability
- Using CTE with filtering and aggregation
- Created simple CTE queries
- Filtered student records using CTE
- Calculated department-wise average marks using CTE
- students
CTE allows complex SQL queries to be written in a cleaner and more readable way.
Today I practiced Subqueries and Common Table Expressions (CTE) in MySQL and compared how the same problem can be solved using both approaches.
- What is a Subquery
- What is a CTE
- Difference between Subquery and CTE
- How CTE improves readability
- Retrieved students scoring above average marks using subquery
- Solved the same problem using CTE
- Compared student marks with department average
- students
Subqueries are useful for nested logic, while CTEs make complex queries easier to read and maintain.
Today I practiced some common SQL interview queries using the students table.
- How to find the second highest value in SQL
- How to retrieve top records using ORDER BY and LIMIT
- How to perform department-wise analysis using GROUP BY
- Found second highest marks using subquery
- Retrieved top 3 students based on marks
- Calculated highest marks for each department
- students
Interview SQL questions often test understanding of subqueries, sorting, and aggregation functions.
Today I practiced how to detect duplicate records in SQL tables.
- What are duplicate records in databases
- How to detect duplicates using GROUP BY and HAVING
- How to retrieve duplicate rows using subqueries
- Basic concept of removing duplicate records
- Identified duplicate student names
- Retrieved duplicate rows from the students table
- Learned the SQL logic used to remove duplicates
- students
Duplicate detection is important for maintaining clean and reliable database records.
Today I built a small SQL project to apply the concepts learned during the MySQL practice journey.
The project simulates a simple student management system with multiple tables.
- students
- courses
- enrollments
- Table creation with primary and foreign keys
- Inserting relational data
- Joining multiple tables
- Performing analytical queries using GROUP BY
Relational databases store data across multiple tables connected through foreign key relationships.
Today I practiced the concept of Running Total using SQL Window Functions.
- What is a running total
- How window functions work in SQL
- Using SUM() with OVER clause
- Created a student_marks table
- Inserted sample student data
- Calculated cumulative marks using SUM window function
Running totals are widely used in analytics and reporting queries to track cumulative values.
Today I practiced the NTILE() window function in MySQL.
- What NTILE() does
- How data can be divided into equal groups
- How NTILE is used for performance segmentation
- Divided students into 4 performance groups
- Ranked students based on marks
- Retrieved top performing students
- student_marks
NTILE() helps divide ordered data into equal segments, commonly used for quartile and percentile analysis.
Today I practiced FIRST_VALUE() and LAST_VALUE() window functions in MySQL.
- What FIRST_VALUE() does
- What LAST_VALUE() does
- Importance of window frame in LAST_VALUE()
- Using window functions for analytics
- Retrieved highest marks using FIRST_VALUE()
- Retrieved lowest marks using LAST_VALUE()
- Combined both in a single query
- student_marks
Window functions like FIRST_VALUE and LAST_VALUE help analyze ordered datasets efficiently.
Today I practiced important SQL interview questions.
- How to find top records per group
- Difference between ROW_NUMBER() and RANK()
- How to solve 2nd highest problems
- Top student per department
- 2nd highest student per department
- Overall 2nd highest marks
- dept_marks
Window functions help solve complex ranking problems efficiently in SQL interviews.