Welcome to the MySQL Practice Repo! 🚀
This repository is perfect for practicing SQL queries including CRUD operations, Joins, Functions, Constraints, and Interview Questions preparation.
- 🔹 100 Most Asked SQL/MySQL Interview Questions
- 🔹 Real-world Use Cases & Scenario-Based Queries
- 🔹 Performance Tips & Optimization Techniques
- 🔹 Window Functions, Joins, Indexing, JSON & More
- Clone the repo
- Read through the markdown or PDF format
- Practice each question with a database like MySQL Workbench, phpMyAdmin, or DB Fiddle
- Revise before your interview or assessment
👉 DDL (Data Definition Language): create, alter, rename, truncate & drop
👉 DQL (Data Query Language): select
👉 DML (Data Manipulation Language): insert, update & delete
👉 DCL (Data Control Language): grant & revoke permission to users
👉 TCL (Transaction Control Language): start transaction, commit, rollback
✔️ Primary Key: It is a column (or set of columns) in a table that uniquely identifies each row. (a unique id) There is only 1 PK & it should be NOT null.
✔️ Foreign Key: A foreign key is a column (or set of columns) in a table that refers to the primary key in another table. FKs can have duplicate & null values.
- 🔧 CRUD Operations
- 📋 Advanced Queries
- 🔗 Joins
- 🧠 Functions & Clauses
- 📎 Constraints
- 💬 Top Interview Questions
- 📂 Sample Database
INSERT INTO employees (id, name, age, department)
VALUES (1, 'Alice', 28, 'IT');
SELECT * FROM employees;
SELECT name, department FROM employees WHERE age > 25;
UPDATE employees
SET department = 'HR'
WHERE id = 1;
DELETE FROM employees
WHERE id = 1;
- 🔢 Aggregate Functions
SELECT COUNT(*) FROM employees;
SELECT AVG(age) FROM employees;
- 🧩 GROUP BY
SELECT department, COUNT(*) FROM employees GROUP BY department;
- 🚫 HAVING
SELECT department, COUNT(*) FROM employees
GROUP BY department
HAVING COUNT(*) > 2;
SELECT e.name, d.name AS dept_name
FROM employees e
INNER JOIN departments d ON e.department_id = d.id;
SELECT e.name, d.name
FROM employees e
LEFT JOIN departments d ON e.department_id = d.id;
- ⏱️
NOW()
– Current timestamp - 🗓️
DATE()
– Extract date - 🔠
UPPER()
,LOWER()
– Case conversion - 🔎
LIKE
,IN
,BETWEEN
– Conditional filters
SELECT * FROM orders
WHERE order_date BETWEEN '2024-01-01' AND '2024-12-31';
SELECT * FROM employees
WHERE name LIKE 'A%';
- 🔑 Primary Key
- 🗝️ Foreign Key
- 🔒 NOT NULL
- 🛡️ UNIQUE
- ✅ CHECK
CREATE TABLE students (
id INT PRIMARY KEY,
name VARCHAR(100) NOT NULL,
age INT CHECK (age >= 18)
);
You can practice with:
employees
👨💼departments
🏢orders
🧾products
🛒students
🎓
Use dummy data or import from Mockaroo for realistic datasets.
Feel free to fork this repo, add new queries, or create issue threads if you find bugs or want improvements!
- ⭐ Star the repository
- 🍴 Fork it
- 📢 Share with friends & developers preparing for interviews
- 🔁 Keep practicing daily!
"Practice makes perfect — keep querying until it's second nature!" 💪