SQL Programming Resources
74.9K subscribers
499 photos
13 files
443 links
Find top SQL resources from global universities, cool projects, and learning materials for data analytics.

Admin: @coderfun

Useful links: heylink.me/DataAnalytics

Promotions: @love_data
Download Telegram
Data Analytics isn't rocket science. It's just a different language.

Here's a beginner's guide to the world of data analytics:

1) Understand the fundamentals:
- Mathematics
- Statistics
- Technology

2) Learn the tools:
- SQL
- Python
- Excel (yes, it's still relevant!)

3) Understand the data:
- What do you want to measure?
- How are you measuring it?
- What metrics are important to you?

4) Data Visualization:
- A picture is worth a thousand words

5) Practice:
- There's no better way to learn than to do it yourself.

Data Analytics is a valuable skill that can help you make better decisions, understand your audience better, and ultimately grow your business.

It's never too late to start learning!
❀7
βœ… SQL Practice Questions with Answers πŸ§ πŸ—ƒοΈ

πŸ” Q1. How to find the 2nd highest salary from a table?
βœ… Answer:
SELECT MAX(salary) FROM employees
WHERE salary < (SELECT MAX(salary) FROM employees);


πŸ” Q2. How to find duplicate values in a column?
βœ… Answer:
SELECT name, COUNT(*) FROM employees
GROUP BY name
HAVING COUNT(*) > 1;


πŸ” Q3. How to select records that exist in one table but not in another?
βœ… Answer:
SELECT * FROM employees
WHERE id NOT IN (SELECT employee_id FROM payroll);


πŸ” Q4. How to get the top 3 highest salaries? (MySQL)
βœ… Answer:
SELECT DISTINCT salary FROM employees
ORDER BY salary DESC
LIMIT 3;


πŸ” Q5. How to fetch employees with the same salary?
βœ… Answer:
SELECT * FROM employees e1
WHERE EXISTS (
SELECT 1 FROM employees e2
WHERE e1.salary = e2.salary AND e1.id <> e2.id
);


πŸ” Q6. How to get the department-wise highest salary?
βœ… Answer:
SELECT department, MAX(salary) AS max_salary
FROM employees
GROUP BY department;


πŸ’¬ Tap ❀️ for more!
❀7πŸ‘1πŸ‘1
βœ… SQL Practice Questions with Answers: Part-2 πŸ§ πŸ—ƒοΈ

πŸ” Q7. Find employees who never received a bonus
πŸ‘€ Table: employees
id | name
1 | Arjun
2 | Riya
3 | Meena

πŸ’° Table: bonus
employee_id | bonus_amount
1 | 3000
3 | 5000

πŸ“„ Query:
SELECT e.id, e.name  
FROM employees e
LEFT JOIN bonus b ON e.id = b.employee_id
WHERE b.employee_id IS NULL;

πŸ“Œ Result: Riya

πŸ” Q8. Get highest salary employee from each department
🧾 Table: employees
id | name | dept | salary
1 | Arjun | HR | 40000
2 | Riya | IT | 55000
3 | Meena | IT | 62000
4 | Kabir | HR | 45000

πŸ“„ Query:
SELECT e.*  
FROM employees e
JOIN (
SELECT department, MAX(salary) AS max_salary
FROM employees
GROUP BY department
) t
ON e.department = t.department
AND e.salary = t.max_salary;

πŸ“Œ Result: Kabir (HR), Meena (IT)

πŸ” Q9. Count number of employees who joined each year
πŸ—“ Table: employees
id | name | join_date
1 | Arjun | 2021-03-10
2 | Riya | 2022-05-12
3 | Meena | 2021-11-03
4 | Kabir | 2023-01-09

πŸ“„ Query:
SELECT YEAR(join_date) AS join_year, COUNT(*) AS total  
FROM employees
GROUP BY YEAR(join_date)
ORDER BY join_year;

πŸ“Œ Result:
2021 β†’ 2
2022 β†’ 1
2023 β†’ 1

πŸ” Q10. Find employees earning more than department average
🧾 Table: employees
id | name | dept | salary
1 | Arjun | HR | 40000
2 | Riya | IT | 55000
3 | Meena | IT | 62000
4 | Kabir | HR | 45000

πŸ“„ Query:
SELECT e.*  
FROM employees e
JOIN (
SELECT department, AVG(salary) AS avg_salary
FROM employees
GROUP BY department
) t
ON e.department = t.department
WHERE e.salary > t.avg_salary;

πŸ“Œ Result: Kabir (HR), Meena (IT)

πŸ” Q11. Fetch the 5th highest salary from employee table
🧾 Table: employees
Salaries: 90000, 85000, 78000, 76000, 72000, 70000

πŸ“„ Query:
SELECT DISTINCT salary  
FROM employees
ORDER BY salary DESC
LIMIT 1 OFFSET 4;

πŸ“Œ Result: 72000

πŸ” Q12. Find employees working on more than one project
πŸ“‚ Table: project_assignments
employee_id | project_id
1 | 101
1 | 102
2 | 103
3 | 104
3 | 105
3 | 106

πŸ“„ Query:
SELECT employee_id, COUNT(*) AS project_count  
FROM project_assignments
GROUP BY employee_id
HAVING COUNT(*) > 1;

πŸ“Œ Result:
1 β†’ 2 projects
3 β†’ 3 projects

πŸ’¬ Tap ❀️ for more!
❀13
βœ… SQL Practice Questions with Answers: Part-3 πŸ§ πŸ—ƒοΈ

πŸ” Q13. Find employees whose salary is above the company average
🧾 Table: employees
id | name | salary
1 | Arjun | 40000
2 | Riya | 55000
3 | Meena | 62000
4 | Kabir | 45000

πŸ“„ Query:
SELECT *  
FROM employees
WHERE salary > (SELECT AVG(salary) FROM employees);

πŸ“Œ Result: Riya, Meena

πŸ” Q14. Get the 3 most recent joined employees
πŸ—“ Table: employees
id | name | join_date
1 | Arjun | 2021-03-10
2 | Riya | 2022-05-12
3 | Meena | 2023-02-01
4 | Kabir | 2023-11-09

πŸ“„ Query:
SELECT *  
FROM employees
ORDER BY join_date DESC
LIMIT 3;

πŸ“Œ Result: Kabir, Meena, Riya

πŸ” Q15. Retrieve employees who don’t have a manager assigned
🧾 Table: employees
id | name | manager_id
1 | Arjun | NULL
2 | Riya | 1
3 | Meena | NULL
4 | Kabir | 2

πŸ“„ Query:
SELECT id, name  
FROM employees
WHERE manager_id IS NULL;

πŸ“Œ Result: Arjun, Meena

πŸ” Q16. Find departments where more than 2 employees work
🧾 Table: employees
id | name | department
1 | Arjun | HR
2 | Riya | IT
3 | Meena | IT
4 | Kabir | HR
5 | John | IT

πŸ“„ Query:
SELECT department, COUNT(*) AS total  
FROM employees
GROUP BY department
HAVING COUNT(*) > 2;

πŸ“Œ Result: IT β†’ 3 employees

πŸ” Q17. Select employees whose salary equals department average
🧾 Table: employees
id | name | dept | salary
1 | Arjun | HR | 40000
2 | Riya | IT | 55000
3 | Meena | IT | 62000
4 | Kabir | HR | 45000

πŸ“„ Query:
SELECT e.*  
FROM employees e
JOIN (
SELECT dept, AVG(salary) AS avg_salary
FROM employees
GROUP BY dept
) t ON e.dept = t.dept
WHERE e.salary = t.avg_salary;

πŸ“Œ Result: None (but logic works if matches exist)

πŸ” Q18. Get employees who have at least one matching project
πŸ“‚ Table: project_assignments
employee_id | project_id
1 | 101
2 | 101
2 | 102
3 | 103
4 | 101

πŸ“„ Query:
SELECT p1.employee_id, p2.employee_id AS colleague  
FROM project_assignments p1
JOIN project_assignments p2
ON p1.project_id = p2.project_id
AND p1.employee_id <> p2.employee_id;

πŸ“Œ Result:
Employees 1, 2, 4 share project 101

πŸ’¬ Tap ❀️ for more!
❀18
βœ… Free Resources to Learn SQL in 2025 πŸ§ πŸ“š

1. YouTube Channels
β€’ freeCodeCamp – Comprehensive SQL courses
β€’ Simplilearn – SQL basics and advanced topics
β€’ CodeWithMosh – SQL tutorial for beginners
β€’ Alex The Analyst – Practical SQL for data analysis

2. Websites
β€’ W3Schools SQL Tutorial – Easy-to-understand basics
β€’ SQLZoo – Interactive SQL tutorials with exercises
β€’ GeeksforGeeks SQL – Concepts, interview questions, and examples
β€’ LearnSQL – Free courses and interactive editor

3. Practice Platforms
β€’ LeetCode (SQL section) – Interview-style SQL problems
β€’ HackerRank (SQL section) – Challenges and practice problems
β€’ StrataScratch – Real-world SQL questions from companies
β€’ SQL Fiddle – Online SQL sandbox for testing queries

4. Free Courses
β€’ Khan Academy: Intro to SQL – Basic database concepts and SQL
β€’ Codecademy: Learn SQL (Basic) – Interactive lessons
β€’ Great Learning: SQL for Beginners – Free certification course
β€’ Udemy (search for free courses) – Many introductory SQL courses often available for free

5. Books for Starters
β€’ β€œSQL in 10 Minutes, Sams Teach Yourself” – Ben Forta
β€’ β€œSQL Practice Problems: 57 Problems to Test Your SQL Skills” – Sylvia Moestl Wasserman
β€’ β€œLearning SQL” – Alan Beaulieu

6. Must-Know Concepts
β€’ SELECT, FROM, WHERE, GROUP BY, HAVING, ORDER BY
β€’ JOINs (INNER, LEFT, RIGHT, FULL)
β€’ Subqueries, CTEs (Common Table Expressions)
β€’ Window Functions (RANK, ROW_NUMBER, LEAD, LAG)
β€’ Basic DDL (CREATE TABLE) and DML (INSERT, UPDATE, DELETE)

πŸ’‘ Practice consistently with real-world scenarios.

πŸ’¬ Tap ❀️ for more!
❀13πŸŽ‰1
βœ… Top 5 Mistakes to Avoid When Learning SQL βŒπŸ“„

1️⃣ Ignoring Data Basics
Don't skip understanding tables, rows, primary keys, and relationships. These are the foundation of SQL.

2️⃣ Memorizing Queries Without Practice
Reading syntax isn't enough. Write real queries on sample databases to retain concepts.

3️⃣ Not Using Joins Early On
Many avoid JOINs thinking they're hard. Practice INNER, LEFT, and RIGHT JOINs with real examples to understand table relationships.

4️⃣ Skipping GROUP BY and Aggregates
GROUP BY with COUNT, SUM, AVG, etc., is core to analytics. Learn it early and use it often.

5️⃣ Not Practicing Real-World Scenarios
Writing SELECT * from a table isn't enough. Use projects like sales reports, user activity tracking, or inventory queries.

πŸ’¬ Tap ❀️ for more!
❀20πŸ‘2
πŸ“Š π—œπ—»π˜π—²π—Ώπ˜ƒπ—Άπ—²π˜„π—²π—Ώ: How do you use CASE in SQL?

πŸ‘‹ 𝗠𝗲: Use CASE to add conditional logic inside SELECT, WHERE, or ORDER BY.

Example:
SELECT name,
salary,
CASE
WHEN salary >= 80000 THEN 'High'
WHEN salary >= 50000 THEN 'Medium'
ELSE 'Low'
END AS salary_level
FROM employees;

🧠 Logic Breakdown:
- Works like if-else
- Evaluates conditions top to bottom
- Returns the first match
- ELSE is optional (defaults to NULL)

βœ… Use Case:
- Create custom categories
- Replace values based on logic
- Conditional ordering or filtering

πŸ’¬ Tap ❀️ for more!
❀17πŸ‘2
βœ… SQL Skills Every Beginner Should Learn πŸ“ŠπŸ’»

1️⃣ Understanding the Basics
⦁ What is a database and table
⦁ Rows, columns, primary keys, foreign keys
⦁ Relational database concepts

2️⃣ Core SQL Queries
⦁ SELECT, FROM, WHERE – Get filtered data
⦁ ORDER BY, LIMIT – Sort and control output
⦁ DISTINCT, BETWEEN, IN, LIKE – Filter smarter

3️⃣ Joins (Combine Tables)
⦁ INNER JOIN – Matching records in both tables
⦁ LEFT JOIN, RIGHT JOIN – Include unmatched from one side
⦁ FULL OUTER JOIN – All records, matched or not

4️⃣ Aggregations
⦁ COUNT(), SUM(), AVG(), MIN(), MAX()
⦁ GROUP BY to summarize data
⦁ HAVING to filter aggregated results

5️⃣ Subqueries & CTEs
⦁ Subquery inside WHERE or SELECT
⦁ WITH clause for clean and reusable code

6️⃣ Window Functions
⦁ ROW_NUMBER(), RANK(), DENSE_RANK()
⦁ PARTITION BY, ORDER BY inside OVER()

7️⃣ Data Cleaning & Logic
⦁ Handle NULL values
⦁ Use CASE WHEN for conditional columns
⦁ Remove duplicates using DISTINCT or ROW_NUMBER()

8️⃣ Practice & Projects
⦁ Sales reports, user activity, inventory tracking
⦁ Work on public datasets
⦁ Solve SQL questions on LeetCode or HackerRank

Double Tap β™₯️ For More
❀13πŸ‘2
βœ… SQL Aggregation & GROUP BY Explained πŸ“ŠπŸ§ 

Aggregation functions are used to summarize data, especially when working with grouped values.

1️⃣ Common Aggregate Functions

⦁ COUNT() – Total number of rows
⦁ SUM() – Adds up numeric values
⦁ AVG() – Calculates the average
⦁ MIN() / MAX() – Finds smallest/largest value

Example:
SELECT department, COUNT(*)  
FROM employees
GROUP BY department;

➑️ Returns the number of employees in each department.

2️⃣ GROUP BY

Used with aggregate functions to group rows based on column values.

SELECT city, AVG(salary)  
FROM employees
GROUP BY city;

➑️ Shows average salary by city.

3️⃣ HAVING vs WHERE

⦁ WHERE filters rows before grouping
⦁ HAVING filters groups after aggregation

Example:
SELECT dept_id, COUNT(*)  
FROM employees
GROUP BY dept_id
HAVING COUNT(*) > 5;

➑️ Shows departments with more than 5 employees.

4️⃣ GROUP BY Multiple Columns
SELECT dept_id, role, COUNT(*)  
FROM employees
GROUP BY dept_id, role;

➑️ Groups by department and role for detailed summaries.

5️⃣ Real-World Use Cases

βœ… Sales by region
βœ… Orders per customer
βœ… Avg. rating per product
βœ… Monthly revenue reports

πŸ’¬ Tap ❀️ for more!
❀16πŸŽ‰2πŸ‘1
βœ… SQL Window Functions πŸͺŸπŸ“Š

Window functions perform calculations across rows related to the current row without collapsing data, unlike GROUP BY.

1️⃣ ROW_NUMBER()
Assigns a unique number to each row within a partition.

SELECT name, dept_id,
ROW_NUMBER() OVER (
PARTITION BY dept_id
ORDER BY salary DESC
) AS rank
FROM employees;


πŸ“Œ *Use case:* Rank employees by salary within each department.


2️⃣ RANK() vs DENSE_RANK()
β€’ RANK() β†’ Skips numbers on ties (1, 2, 2, 4)
β€’ DENSE_RANK() β†’ No gaps (1, 2, 2, 3)

SELECT name, salary,
RANK() OVER (ORDER BY salary DESC) AS rnk,
DENSE_RANK() OVER (ORDER BY salary DESC) AS dense_rnk
FROM employees;



3️⃣ LAG() & LEAD()
Access previous or next row values.

SELECT name, salary,
LAG(salary) OVER (ORDER BY id) AS prev_salary,
LEAD(salary) OVER (ORDER BY id) AS next_salary
FROM employees;


πŸ“Œ Use case: Compare current vs previous/next values
(e.g., salary change, stock price movement).

4️⃣ NTILE(n)
Divides rows into *n* equal buckets.

SELECT name,
NTILE(4) OVER (ORDER BY salary DESC) AS quartile
FROM employees;


πŸ“Œ Use case: Quartiles & percentile-based analysis.


5️⃣ Aggregates with OVER()
Running totals & partition-wise calculations.

SELECT name, dept_id, salary,
SUM(salary) OVER (PARTITION BY dept_id) AS dept_total
FROM employees;


🧠 Interview Q&A

Q1️⃣ GROUP BY vs OVER()?
β€’ GROUP BY β†’ Collapses rows (one row per group)
β€’ OVER() β†’ Keeps all rows and adds calculated columns

Q2️⃣ When to use LAG()?
To compare current row with previous data
(e.g., daily revenue change, previous month balance).

Q3️⃣ No PARTITION BY used?
The function runs over the entire result set.

Q4️⃣ Can we use ORDER BY inside OVER()?
βœ… Yes. Required for ranking, LAG/LEAD, running totals.

πŸ’¬ Double tap ❀️ & share for more SQL tips! πŸš€
❀10πŸ‘1
βœ… SQL Basics You Should Know πŸ’»πŸ“Š

1️⃣ What is SQL?
SQL (Structured Query Language) is a standardized language used to manage and manipulate relational databases.

2️⃣ Most Common SQL Commands:
β€’ SELECT – fetch data
β€’ INSERT – add data
β€’ UPDATE – modify existing data
β€’ DELETE – remove data
β€’ CREATE – create a new table or database
β€’ DROP – delete a table or database

3️⃣ Filtering Data:
To filter records based on conditions:
SELECT * FROM employees WHERE salary > 50000;


4️⃣ Sorting Data:
To sort results in ascending or descending order:
SELECT name FROM students ORDER BY marks DESC;


5️⃣ Using Functions:
Common aggregate functions:
β€’ COUNT() – counts the number of records
β€’ AVG() – calculates the average value
β€’ MAX() / MIN() – returns the highest/lowest value
β€’ SUM() – computes the total sum

6️⃣ Grouping Data:
To group records and perform calculations:
SELECT department, COUNT(*) FROM employees GROUP BY department;


7️⃣ Joins:
Combining rows from two or more tables based on related columns:
β€’ INNER JOIN: Returns matching records in both tables
β€’ LEFT JOIN: Returns all records from the left table and matching records from the right table
β€’ RIGHT JOIN: Returns all records from the right table and matching records from the left table
β€’ FULL JOIN: Returns all records when there is a match in either left or right table

8️⃣ Aliases:
To rename a column or table for readability:
SELECT name AS employee_name FROM employees;


9️⃣ Subqueries:
Using a query within another query:
SELECT name FROM students WHERE marks > (SELECT AVG(marks) FROM students);


πŸ”Ÿ Real Use Cases:
β€’ Managing employee records
β€’ Generating sales reports
β€’ Tracking inventory levels
β€’ Analyzing customer insights

πŸ’¬ Tap ❀️ for more SQL tips and tricks!
❀17πŸ‘1
βœ… Useful SQL Concepts You Should Know πŸš€πŸ“ˆ

1️⃣ Constraints in SQL:

- PRIMARY KEY – Uniquely identifies each row
- FOREIGN KEY – Links to another table
- UNIQUE – Ensures all values are different
- NOT NULL – Column must have a value
- CHECK – Validates data before insert/update

2️⃣ SQL Views:

Virtual tables based on result of a query
CREATE VIEW top_students AS
SELECT name, marks FROM students WHERE marks > 90;

3️⃣ Indexing:

Improves query performance
CREATE INDEX idx_name ON employees(name);

4️⃣ SQL Transactions:

Ensure data integrity
BEGIN;
UPDATE accounts SET balance = balance - 100 WHERE id = 1;
UPDATE accounts SET balance = balance + 100 WHERE id = 2;
COMMIT;

5️⃣ Triggers:

Automatic actions when events occur
CREATE TRIGGER log_update
AFTER UPDATE ON employees
FOR EACH ROW
INSERT INTO logs(action) VALUES ('Employee updated');

6️⃣ Stored Procedures:

Reusable blocks of SQL logic
CREATE PROCEDURE getTopStudents()
BEGIN
SELECT * FROM students WHERE marks > 90;
END;

7️⃣ Common Table Expressions (CTEs):

Temporary named result sets
WITH dept_count AS (
SELECT department, COUNT(*) AS total FROM employees GROUP BY department
)
SELECT * FROM dept_count;

πŸ’¬ Double Tap ❀️ For More!
❀15
βœ… SQL Coding Questions with Answers: Part-1 πŸ“ŠπŸ’»

1️⃣ Get the Second Highest Salary
Table: Employees
| id | name | salary |
|----|---------|--------|
| 1 | Alice | 5000 |
| 2 | Bob | 7000 |
| 3 | Charlie | 7000 |
| 4 | David | 6000 |

Query:
SELECT MAX(salary) AS Second_Highest
FROM Employees
WHERE salary < (
SELECT MAX(salary) FROM Employees
);

This returns the highest salary less than the maximumβ€”i.e., the second highest.

2️⃣ Count Employees Per Department
Table: Employees
| id | name | dept |
|----|--------|--------|
| 1 | Alice | HR |
| 2 | Bob | IT |
| 3 | Clara | IT |
| 4 | Dan | Sales |

Query:
SELECT dept, COUNT(*) AS total_employees  
FROM Employees
GROUP BY dept;

This groups employees by department and counts how many are in each.

3️⃣ Find Duplicate Emails
Table: Users
| id | email |
|----|------------------|
| 1 | [email protected] |
| 2 | [email protected] |
| 3 | [email protected] |

Query:
SELECT email, COUNT(*) AS count  
FROM Users
GROUP BY email
HAVING COUNT(*) > 1;

Returns all emails that appear more than once.

4️⃣ Get Top 2 Salaries Per Department
Table: Employees
| id | name | dept | salary |
|----|--------|-------|--------|
| 1 | Alice | IT | 7000 |
| 2 | Bob | IT | 6500 |
| 3 | Clara | HR | 6000 |
| 4 | Dan | HR | 5900 |

Query:
SELECT * FROM (
SELECT *, RANK() OVER (PARTITION BY dept ORDER BY salary DESC) AS rnk
FROM Employees
) AS ranked
WHERE rnk <= 2;

Ranks salaries within each department and returns top 2 per group.

5️⃣ Employees With No Manager Assigned
Table: Employees
| id | name | manager_id |
|----|-------|------------|
| 1 | John | NULL |
| 2 | Sarah | 1 |
| 3 | Alex | 2 |

Query:
SELECT * FROM Employees  
WHERE manager_id IS NULL;

Returns employees without any assigned manager.

πŸ’¬ Double Tap ❀️ for Part-2!
❀14
βœ… SQL Coding Interview Questions with Answers – Part 2 πŸ“šπŸ’»

1️⃣ Find Employees Who Earn More Than Their Manager
Table: Employees
| id | name | salary | manager_id |
|----|--------|--------|------------|
| 1 | Alice | 8000 | NULL |
| 2 | Bob | 6000 | 1 |
| 3 | Clara | 9000 | 1 |
| 4 | Dan | 5000 | 2 |

Query:
SELECT e.name  
FROM Employees e
JOIN Employees m ON e.manager_id = m.id
WHERE e.salary > m.salary;

*Finds employees whose salary is greater than their manager’s.*

2️⃣ Find Departments With More Than 3 Employees
Table: Employees
| id | name | dept |
|----|-------|-------|
| 1 | Alice | IT |
| 2 | Bob | IT |
| 3 | Clara | HR |
| 4 | Dan | IT |
| 5 | Eva | IT |

Query:
SELECT dept  
FROM Employees
GROUP BY dept
HAVING COUNT(*) > 3;

*Lists departments that have more than 3 people.*

3️⃣ Find Employees Who Joined in Last 30 Days
Table: Employees
| id | name | join_date |
|----|-------|------------|
| 1 | Alice | 2023-11-10 |
| 2 | Bob | 2023-12-15 |
| 3 | Clara | 2023-12-25 |

Query:
SELECT * FROM Employees  
WHERE join_date >= CURRENT_DATE - INTERVAL 30 DAY;

*Shows all recent joiners.*

4️⃣ Find Common Records in Two Tables
Tables: A B
| A.id |
|------|
| 1 |
| 2 |
| 3 |

| B.id |
|------|
| 2 |
| 3 |
| 4 |

Query:
SELECT A.id  
FROM A
INNER JOIN B ON A.id = B.id;

*Returns IDs that are present in both tables.*

5️⃣ List Employees with Same Salary
Table: Employees
| id | name | salary |
|----|-------|--------|
| 1 | Alice | 5000 |
| 2 | Bob | 6000 |
| 3 | Dan | 5000 |

Query:
SELECT salary  
FROM Employees
GROUP BY salary
HAVING COUNT(*) > 1;

*Then join it back if you want full details:*
SELECT * FROM Employees  
WHERE salary IN (
SELECT salary
FROM Employees
GROUP BY salary
HAVING COUNT(*) > 1
);


πŸ’¬ Tap ❀️ for Part-3!
❀10
βœ… SQL Coding Interview Questions with Answers: Part 3 πŸ“ŠπŸ’»

1️⃣ Get Highest Salary Per Department
Table: Employees
Columns: id, name, dept, salary

SELECT dept, MAX(salary) AS highest_salary  
FROM Employees
GROUP BY dept;

Use case: Department-wise pay analysis.

2️⃣ Find Employees Without Matching Department
Tables: Employees, Departments

SELECT e.*  
FROM Employees e
LEFT JOIN Departments d
ON e.dept_id = d.id
WHERE d.id IS NULL;

Use case: Data quality checks after joins.

3️⃣ Delete Duplicate Records but Keep One
Table: Users
Column: email

DELETE FROM Users  
WHERE id NOT IN (
SELECT MIN(id)
FROM Users
GROUP BY email
);

Use case: Cleanup before analytics.

4️⃣ Find Nth Highest Salary (Example: 3rd)
Table: Employees

SELECT salary  
FROM (
SELECT salary,
DENSE_RANK() OVER (ORDER BY salary DESC) AS rnk
FROM Employees
) t
WHERE rnk = 3;

Use case: Works even with duplicate salaries.

5️⃣ Swap Gender Values
Table: Employees
Column: gender (M, F)

UPDATE Employees  
SET gender =
CASE
WHEN gender = 'M' THEN 'F'
WHEN gender = 'F' THEN 'M'
END;

Use case: Data correction tasks.

6️⃣ Find Employees with Odd IDs
Table: Employees

SELECT *  
FROM Employees
WHERE id % 2 = 1;

Use case: Common filter logic question.

7️⃣ Get Running Total of Salary
Table: Employees
Column: salary

SELECT id, salary,  
SUM(salary) OVER (ORDER BY id) AS running_total
FROM Employees;

Use case: Used in financial and growth reports.

πŸ’¬ Tap ❀️ for Part 4!
❀9πŸ‘1
βœ… SQL Coding Interview Questions with Answers: Part 4 πŸ“˜πŸ’»

1️⃣ Retrieve Employees with the Highest Salary in Each Department (Full Details)
Table: Employees
Columns: id, name, dept, salary
SELECT *
FROM Employees e
WHERE salary = (
SELECT MAX(salary)
FROM Employees
WHERE dept = e.dept
);


🧠 _Use case:_ Get full employee details, not just the salary, for top earners per department.

2️⃣ Find Departments Without Employees
Tables: Departments (id, name), Employees (id, name, dept_id)
SELECT d.*
FROM Departments d
LEFT JOIN Employees e ON d.id = e.dept_id
WHERE e.id IS NULL;


🧠 _Use case:_ Identify departments that haven’t been staffed yet.

3️⃣ Rank Employees by Salary Within Department (With Ties)
Table: Employees
SELECT id, name, dept, salary,
RANK() OVER (PARTITION BY dept ORDER BY salary DESC) AS salary_rank
FROM Employees;


🧠 _Use case:_ Useful for performance reviews or compensation analysis.

4️⃣ Find Consecutive Login Days Per User
Table: Logins (user_id, login_date)
SELECT user_id, login_date,
DATEDIFF(login_date,
ROW_NUMBER() OVER (PARTITION BY user_id ORDER BY login_date)) AS grp
FROM Logins;


🧠 _Use case:_ Group by user_id and grp to find streaks of consecutive logins.

5️⃣ Get Employees with the Minimum Salary in the Company
Table: Employees
SELECT *
FROM Employees
WHERE salary = (SELECT MIN(salary) FROM Employees);


🧠 _Use case:_ Identify underpaid or entry-level employees.

6️⃣ Find Managers Who Don’t Have Any Direct Reports
Table: Employees (id, name, manager_id)
SELECT *
FROM Employees
WHERE id NOT IN (
SELECT DISTINCT manager_id
FROM Employees
WHERE manager_id IS NOT NULL
);


🧠 Use case: Spot inactive or placeholder managers.

πŸ’¬ Double Tap ❀️ For More
❀16πŸ‘1
Most Asked SQL Interview Questions at MAANG CompaniesπŸ”₯πŸ”₯

Preparing for an SQL Interview at MAANG Companies? Here are some crucial SQL Questions you should be ready to tackle:

1. How do you retrieve all columns from a table?

SELECT * FROM table_name;

2. What SQL statement is used to filter records?

SELECT * FROM table_name
WHERE condition;

The WHERE clause is used to filter records based on a specified condition.

3. How can you join multiple tables? Describe different types of JOINs.

SELECT columns
FROM table1
JOIN table2 ON table1.column = table2.column
JOIN table3 ON table2.column = table3.column;

Types of JOINs:

1. INNER JOIN: Returns records with matching values in both tables

SELECT * FROM table1
INNER JOIN table2 ON table1.column = table2.column;

2. LEFT JOIN: Returns all records from the left table & matched records from the right table. Unmatched records will have NULL values.

SELECT * FROM table1
LEFT JOIN table2 ON table1.column = table2.column;

3. RIGHT JOIN: Returns all records from the right table & matched records from the left table. Unmatched records will have NULL values.

SELECT * FROM table1
RIGHT JOIN table2 ON table1.column = table2.column;

4. FULL JOIN: Returns records when there is a match in either left or right table. Unmatched records will have NULL values.

SELECT * FROM table1
FULL JOIN table2 ON table1.column = table2.column;

4. What is the difference between WHERE & HAVING clauses?

WHERE: Filters records before any groupings are made.

SELECT * FROM table_name
WHERE condition;

HAVING: Filters records after groupings are made.

SELECT column, COUNT(*)
FROM table_name
GROUP BY column
HAVING COUNT(*) > value;

5. How do you calculate average, sum, minimum & maximum values in a column?

Average: SELECT AVG(column_name) FROM table_name;

Sum: SELECT SUM(column_name) FROM table_name;

Minimum: SELECT MIN(column_name) FROM table_name;

Maximum: SELECT MAX(column_name) FROM table_name;

Here you can find essential SQL Interview ResourcesπŸ‘‡
https://t.iss.one/mysqldata

Like this post if you need more πŸ‘β€οΈ

Hope it helps :)
❀10πŸ‘1
βœ… Top SQL Queries: Part-1 πŸ§ πŸ’»

1️⃣ SELECT – Retrieve Data
πŸ”Ή Use case: Show all employees
SELECT * FROM employees;

2️⃣ WHERE – Filter Data
πŸ”Ή Use case: Get employees from β€˜Sales’ department
SELECT name FROM employees WHERE department = 'Sales';

3️⃣ ORDER BY – Sort Results
πŸ”Ή Use case: List products by price (low to high)
SELECT product_name, price FROM products ORDER BY price ASC;

4️⃣ GROUP BY – Aggregate Data
πŸ”Ή Use case: Count employees in each department
SELECT department, COUNT(*) FROM employees GROUP BY department;

5️⃣ JOIN – Combine Tables
πŸ”Ή Use case: Show orders with customer names
SELECT o.order_id, c.customer_name
FROM orders o
JOIN customers c ON o.customer_id = c.id;

6️⃣ INSERT – Add New Records
πŸ”Ή Use case: Add a new product
INSERT INTO products (name, price, category)
VALUES ('Headphones', 1500, 'Electronics');

7️⃣ UPDATE – Modify Existing Records
πŸ”Ή Use case: Change price of 'Headphones'
UPDATE products SET price = 1700 WHERE name = 'Headphones';

8️⃣ DELETE – Remove Data
πŸ”Ή Use case: Delete users inactive for 1 year
DELETE FROM users WHERE last_login < '2024-01-01';

9️⃣ LIKE – Pattern Matching
πŸ”Ή Use case: Find customers whose names start with 'A'
SELECT * FROM customers WHERE name LIKE 'A%';

πŸ”Ÿ LIMIT – Restrict Output
πŸ”Ή Use case: Show top 3 most expensive items
SELECT name, price FROM products ORDER BY price DESC LIMIT 3;

πŸ’¬ Tap ❀️ for Part 2!
❀14πŸ‘1
πŸš€ Roadmap to Master SQL in 30 Days! πŸ—ƒοΈπŸ§ 

πŸ“… Week 1: SQL Basics
πŸ”Ή Day 1–2: What is SQL? DBMS vs RDBMS
πŸ”Ή Day 3–5: SELECT, WHERE, ORDER BY, LIMIT
πŸ”Ή Day 6–7: Filtering with AND, OR, IN, NOT, BETWEEN

πŸ“… Week 2: Intermediate SQL
πŸ”Ή Day 8–9: Functions (COUNT, SUM, AVG, MIN, MAX)
πŸ”Ή Day 10–11: GROUP BY, HAVING
πŸ”Ή Day 12–14: JOINS (INNER, LEFT, RIGHT, FULL)

πŸ“… Week 3: Advanced SQL
πŸ”Ή Day 15–17: Subqueries Nested Queries
πŸ”Ή Day 18–20: CASE statements, COALESCE, NULL handling
πŸ”Ή Day 21–22: Window Functions (ROW_NUMBER, RANK, PARTITION BY)

πŸ“… Week 4: Practical Use Projects
πŸ”Ή Day 23–25: Views, Indexes, Stored Procedures (basic)
πŸ”Ή Day 26–28: Real-world project (e.g., Sales dashboard with queries)
πŸ”Ή Day 29–30: Practice on platforms like LeetCode, HackerRank, Mode

πŸ’‘ Bonus Tools:
β€’ MySQL / PostgreSQL / SQLite
β€’ DB Fiddle / SQLZoo / W3Schools
β€’ Power BI / Excel for data connection

πŸ’¬ Tap ❀️ for more!
❀28πŸ‘1
Today, let's start with the complete SQL series starting with the basics:

βœ… SQL Basics: Part-1 πŸ§ πŸ’Ύ

SQL (Structured Query Language) is the standard language used to communicate with databases.
You use it to store, retrieve, update, and delete data in a structured format.

πŸ› οΈ Why Learn SQL?
β€’ It’s used in data analytics, development, and business intelligence.
β€’ Works with tools like Power BI, Excel, Python, Tableau, etc.
β€’ Helps in querying and analyzing large datasets efficiently.

πŸ“š Key Concepts:

1️⃣ DBMS (Database Management System)
β€’ A software to manage databases.
β€’ Stores data in files or documents.
β€’ Examples: Microsoft Access, MongoDB (non-relational).
β€’ No strict structure or rules.

2️⃣ RDBMS (Relational Database Management System)
β€’ Stores data in tables with rows and columns.
β€’ Ensures data consistency using relationships.
β€’ Follows ACID properties (Atomicity, Consistency, Isolation, Durability).
β€’ Examples: MySQL, PostgreSQL, Oracle, SQL Server.

πŸ—‚οΈ Simple Table Example (in RDBMS):

Customers Table
❀8πŸ‘2
πŸ‘3πŸ€”2