β
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
π§ _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)
π§ _Use case:_ Identify departments that havenβt been staffed yet.
3οΈβ£ Rank Employees by Salary Within Department (With Ties)
Table: Employees
π§ _Use case:_ Useful for performance reviews or compensation analysis.
4οΈβ£ Find Consecutive Login Days Per User
Table: Logins (user_id, login_date)
π§ _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
π§ _Use case:_ Identify underpaid or entry-level employees.
6οΈβ£ Find Managers Who Donβt Have Any Direct Reports
Table: Employees (id, name, manager_id)
π§ Use case: Spot inactive or placeholder managers.
π¬ Double Tap β€οΈ For More
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 :)
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!
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!
π 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
β 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
β€7π2
You can use SQL to:
β‘οΈ This returns all records from the table. (Note: The
π Real-life Analogy:
Think of RDBMS as Excel β rows are records, columns are fields.
SQL is the language to ask questions like:
- Who are my customers from Delhi?
- What is the total number of orders last month?
π― Task for You Today:
β Install MySQL or use an online SQL editor (like SQLFiddle)
β Learn basic syntax: SELECT, FROM
β Try creating a sample table and selecting data
π¬ Tap β€οΈ for Part-2
SELECT * FROM Customers; β‘οΈ This returns all records from the table. (Note: The
* here is a wildcard meaning "all columns").π Real-life Analogy:
Think of RDBMS as Excel β rows are records, columns are fields.
SQL is the language to ask questions like:
- Who are my customers from Delhi?
- What is the total number of orders last month?
π― Task for You Today:
β Install MySQL or use an online SQL editor (like SQLFiddle)
β Learn basic syntax: SELECT, FROM
β Try creating a sample table and selecting data
π¬ Tap β€οΈ for Part-2
β€19π1
β
SQL Basics: Part-2 (SQL Commands) π§ πΎ
1οΈβ£ SELECT β Pull data from a table
_Syntax:_
_Example:_
To get _everything_ use:
2οΈβ£ WHERE β Filter specific rows
_Syntax:_
_Example:_
_Operators you can use:_
β’ =, !=, >, <, >=, <=
β’ LIKE (pattern match)
β’ BETWEEN, IN, IS NULL
3οΈβ£ ORDER BY β Sort results
_Syntax:_
_Example:_
4οΈβ£ LIMIT β Restrict number of results
_Syntax:_
_Example:_
π₯ _Quick Practice Task:_
Write a query to:
β’ Get top 10 highest-paid employees in 'Marketing'
β’ Show name, salary, and department
β’ Sort salary high to low:
β SQL Interview QA πΌπ§
Q1. What does the SELECT statement do in SQL?
_Answer:_
It retrieves data from one or more columns in a table.
Q2. How would you fetch all the columns from a table?
_Answer:_
Use SELECT * to get every column.
Q3. Whatβs the difference between WHERE and HAVING?
_Answer:_
β’ WHERE filters rows _before_ grouping
β’ HAVING filters _after_ GROUP BY
You use WHERE with raw data, HAVING with aggregated data.
Q4. Write a query to find all products with price > 500.
_Answer:_
Q5. How do you sort data by two columns?
_Answer:_
Use ORDER BY col1, col2.
Q6. What does LIMIT 1 do in a query?
_Answer:_
It returns only the _first row_ of the result.
Q7. Write a query to get names of top 5 students by marks.
_Answer:_
Q8. Can you use ORDER BY without WHERE?
_Answer:_
Yes. ORDER BY works independently. It sorts all data unless filtered with WHERE.
π‘ _Pro Tip:_
In interviews, they may ask you to _write queries live_ or explain the _output_ of a query. Stay calm, read the structure carefully, and _think in steps_.
DOUBLE TAP β€οΈ FOR MORE
1οΈβ£ SELECT β Pull data from a table
_Syntax:_
SELECT column1, column2 FROM table_name;
_Example:_
SELECT name, city FROM customers;
To get _everything_ use:
SELECT * FROM customers;
2οΈβ£ WHERE β Filter specific rows
_Syntax:_
SELECT columns FROM table_name WHERE condition;
_Example:_
SELECT name FROM customers WHERE city = 'Delhi';
_Operators you can use:_
β’ =, !=, >, <, >=, <=
β’ LIKE (pattern match)
β’ BETWEEN, IN, IS NULL
3οΈβ£ ORDER BY β Sort results
_Syntax:_
SELECT columns FROM table_name ORDER BY column ASC|DESC;
_Example:_
SELECT name, age FROM employees ORDER BY age DESC;
4οΈβ£ LIMIT β Restrict number of results
_Syntax:_
SELECT columns FROM table_name LIMIT number;
_Example:_
SELECT * FROM products LIMIT 5;
π₯ _Quick Practice Task:_
Write a query to:
β’ Get top 10 highest-paid employees in 'Marketing'
β’ Show name, salary, and department
β’ Sort salary high to low:
SELECT name, salary, department
FROM employees
WHERE department = 'Marketing'
ORDER BY salary DESC
LIMIT 10;
β SQL Interview QA πΌπ§
Q1. What does the SELECT statement do in SQL?
_Answer:_
It retrieves data from one or more columns in a table.
SELECT name, city FROM customers;
Q2. How would you fetch all the columns from a table?
_Answer:_
Use SELECT * to get every column.
SELECT * FROM orders;
Q3. Whatβs the difference between WHERE and HAVING?
_Answer:_
β’ WHERE filters rows _before_ grouping
β’ HAVING filters _after_ GROUP BY
You use WHERE with raw data, HAVING with aggregated data.
Q4. Write a query to find all products with price > 500.
_Answer:_
SELECT * FROM products WHERE price > 500;
Q5. How do you sort data by two columns?
_Answer:_
Use ORDER BY col1, col2.
SELECT name, department FROM employees ORDER BY department ASC, name ASC;
Q6. What does LIMIT 1 do in a query?
_Answer:_
It returns only the _first row_ of the result.
SELECT * FROM customers ORDER BY created_at DESC LIMIT 1;
Q7. Write a query to get names of top 5 students by marks.
_Answer:_
SELECT name, marks
FROM students
ORDER BY marks DESC
LIMIT 5;
Q8. Can you use ORDER BY without WHERE?
_Answer:_
Yes. ORDER BY works independently. It sorts all data unless filtered with WHERE.
π‘ _Pro Tip:_
In interviews, they may ask you to _write queries live_ or explain the _output_ of a query. Stay calm, read the structure carefully, and _think in steps_.
DOUBLE TAP β€οΈ FOR MORE
β€14π1
β
SQL Basics: Part-3: Filtering with SQL Operators
Filtering helps you narrow down results based on specific conditions.
Letβs explore some powerful SQL operators:
1οΈβ£ IN β Match multiple values
Syntax:
Example:
Get customers from specific cities:
2οΈβ£ OR β Match any of multiple conditions
Syntax:
Example:
Get employees from HR or Finance:
3οΈβ£ AND β Match all conditions
Syntax:
Example:
Get Sales employees earning more than 60,000:
4οΈβ£ NOT β Exclude specific values or conditions
Syntax:
Example:
Get all products except Electronics:
5οΈβ£ BETWEEN β Match a range of values (inclusive)
Syntax:
Example:
Get employees with salary between 50,000 and 100,000:
π₯ Quick Practice Task:
Write a query to:
β’ Get all employees in 'IT' or 'HR'
β’ Who earn more than 50,000
β’ Show name, department, and salary:
β SQL Filtering Interview QA πΌπ§
Q1. Whatβs the difference between AND and OR?
A:
β’ AND requires all conditions to be true
β’ OR requires at least one condition to be true
Q2. Can you combine AND and OR in one query?
A: Yes, but use parentheses to control logic:
Q3. What does NOT IN do?
A: Excludes rows with values in the list:
Q4. Can BETWEEN be used with dates?
A: Absolutely!
Q5. Whatβs the difference between IN and multiple ORs?
A: IN is cleaner and more concise:
-- Instead of:
-- Use:
π‘ Pro Tip:
When combining multiple filters, always use parentheses to avoid unexpected results due to operator precedence.
SQL Roadmap
DOUBLE TAP β€οΈ FOR MORE
Filtering helps you narrow down results based on specific conditions.
Letβs explore some powerful SQL operators:
1οΈβ£ IN β Match multiple values
Syntax:
SELECT columns FROM table_name WHERE column IN (value1, value2,...);
Example:
Get customers from specific cities:
SELECT name, city FROM customers
WHERE city IN ('Delhi', 'Mumbai', 'Chennai');
2οΈβ£ OR β Match any of multiple conditions
Syntax:
SELECT columns FROM table_name WHERE condition1 OR condition2;
Example:
Get employees from HR or Finance:
SELECT name FROM employees
WHERE department = 'HR' OR department = 'Finance';
3οΈβ£ AND β Match all conditions
Syntax:
SELECT columns FROM table_name WHERE condition1 AND condition2;
Example:
Get Sales employees earning more than 60,000:
SELECT name FROM employees
WHERE department = 'Sales' AND salary > 60000;
4οΈβ£ NOT β Exclude specific values or conditions
Syntax:
SELECT columns FROM table_name WHERE NOT condition;
Example:
Get all products except Electronics:
SELECT * FROM products
WHERE NOT category = 'Electronics';
5οΈβ£ BETWEEN β Match a range of values (inclusive)
Syntax:
SELECT columns FROM table_name WHERE column BETWEEN value1 AND value2;
Example:
Get employees with salary between 50,000 and 100,000:
SELECT name, salary FROM employees
WHERE salary BETWEEN 50000 AND 100000;
π₯ Quick Practice Task:
Write a query to:
β’ Get all employees in 'IT' or 'HR'
β’ Who earn more than 50,000
β’ Show name, department, and salary:
SELECT name, department, salary
FROM employees
WHERE department IN ('IT', 'HR')
AND salary > 50000;
β SQL Filtering Interview QA πΌπ§
Q1. Whatβs the difference between AND and OR?
A:
β’ AND requires all conditions to be true
β’ OR requires at least one condition to be true
Q2. Can you combine AND and OR in one query?
A: Yes, but use parentheses to control logic:
SELECT * FROM employees
WHERE (department = 'Sales' OR department = 'Marketing')
AND salary > 60000;
Q3. What does NOT IN do?
A: Excludes rows with values in the list:
SELECT * FROM customers
WHERE city NOT IN ('Delhi', 'Mumbai');
Q4. Can BETWEEN be used with dates?
A: Absolutely!
SELECT * FROM orders
WHERE order_date BETWEEN '2025-01-01' AND '2025-01-31';
Q5. Whatβs the difference between IN and multiple ORs?
A: IN is cleaner and more concise:
-- Instead of:
WHERE city = 'A' OR city = 'B' OR city = 'C';
-- Use:
WHERE city IN ('A', 'B', 'C');π‘ Pro Tip:
When combining multiple filters, always use parentheses to avoid unexpected results due to operator precedence.
SQL Roadmap
DOUBLE TAP β€οΈ FOR MORE
β€11
β
SQL Functions ππ§
SQL functions are built-in operations used to manipulate, calculate, and transform data. They help in summarizing results, formatting values, and applying logic in queries.
1οΈβ£ Aggregate Functions
These return a single result from a group of rows.
β’ COUNT() β Counts rows
β’ SUM() β Adds values
β’ AVG() β Returns average
β’ MAX() / MIN() β Highest or lowest value
2οΈβ£ String Functions
β’ UPPER() / LOWER() β Change case
β’ CONCAT() β Join strings
β’ SUBSTRING() β Extract part of a string
β’ LENGTH() β Length of string
3οΈβ£ Date Functions
β’ CURRENT_DATE / NOW() β Current date/time
β’ DATE_ADD() / DATE_SUB() β Add or subtract days
β’ DATEDIFF() β Difference between dates
β’ YEAR() / MONTH() / DAY() β Extract parts
4οΈβ£ Mathematical Functions
β’ ROUND() β Round decimals
β’ CEIL() / FLOOR() β Round up/down
β’ ABS() β Absolute value
5οΈβ£ Conditional Function
β’ COALESCE() β Returns first non-null value
β’ CASE β If/else logic in SQL
π― Use These Functions To:
β’ Summarize data
β’ Clean and format strings
β’ Handle nulls
β’ Calculate time differences
β’ Add logic into queries
π¬ Tap β€οΈ for more!
SQL functions are built-in operations used to manipulate, calculate, and transform data. They help in summarizing results, formatting values, and applying logic in queries.
1οΈβ£ Aggregate Functions
These return a single result from a group of rows.
β’ COUNT() β Counts rows
SELECT COUNT(*) FROM employees;β’ SUM() β Adds values
SELECT SUM(salary) FROM employees WHERE department = 'IT';β’ AVG() β Returns average
SELECT AVG(age) FROM customers;β’ MAX() / MIN() β Highest or lowest value
SELECT MAX(salary), MIN(salary) FROM employees;2οΈβ£ String Functions
β’ UPPER() / LOWER() β Change case
SELECT UPPER(name), LOWER(city) FROM customers;β’ CONCAT() β Join strings
SELECT CONCAT(first_name, ' ', last_name) AS full_name FROM users;β’ SUBSTRING() β Extract part of a string
SELECT SUBSTRING(name, 1, 3) FROM products;β’ LENGTH() β Length of string
SELECT LENGTH(description) FROM products;3οΈβ£ Date Functions
β’ CURRENT_DATE / NOW() β Current date/time
SELECT CURRENT_DATE, NOW();β’ DATE_ADD() / DATE_SUB() β Add or subtract days
SELECT DATE_ADD(hire_date, INTERVAL 30 DAY) FROM employees;β’ DATEDIFF() β Difference between dates
SELECT DATEDIFF(end_date, start_date) FROM projects;β’ YEAR() / MONTH() / DAY() β Extract parts
SELECT YEAR(order_date), MONTH(order_date) FROM orders;4οΈβ£ Mathematical Functions
β’ ROUND() β Round decimals
SELECT ROUND(price, 2) FROM products;β’ CEIL() / FLOOR() β Round up/down
SELECT CEIL(4.2), FLOOR(4.8);β’ ABS() β Absolute value
SELECT ABS(balance) FROM accounts;5οΈβ£ Conditional Function
β’ COALESCE() β Returns first non-null value
SELECT COALESCE(phone, 'Not Provided') FROM customers;β’ CASE β If/else logic in SQL
SELECT name,
CASE
WHEN salary > 50000 THEN 'High'
WHEN salary BETWEEN 30000 AND 50000 THEN 'Medium'
ELSE 'Low'
END AS salary_band
FROM employees;
π― Use These Functions To:
β’ Summarize data
β’ Clean and format strings
β’ Handle nulls
β’ Calculate time differences
β’ Add logic into queries
π¬ Tap β€οΈ for more!
β€10π2
β
SQL GROUP BY HAVING π
What is GROUP BY?
GROUP BY is used to group rows that have the same values in one or more columns. Itβs mostly used with aggregate functions like SUM(), COUNT(), AVG() to get summarized results.
What is HAVING?
HAVING is like WHERE, but it works after grouping. It filters the grouped results. You canβt use aggregate functions in WHERE, so we use HAVING instead.
π Problem 1:
You want to find total sales made in each city.
β This groups the sales by city and shows total per group.
π Problem 2:
Now, show only those cities where total sales are above βΉ50,000.
β `HAVING filters the result after grouping.
π Problem 3:
Find departments with more than 10 active employees.
β First, we filter rows using
π‘ Use
Double Tap β₯οΈ For More
What is GROUP BY?
GROUP BY is used to group rows that have the same values in one or more columns. Itβs mostly used with aggregate functions like SUM(), COUNT(), AVG() to get summarized results.
What is HAVING?
HAVING is like WHERE, but it works after grouping. It filters the grouped results. You canβt use aggregate functions in WHERE, so we use HAVING instead.
π Problem 1:
You want to find total sales made in each city.
SELECT city, SUM(sales) AS total_sales
FROM customers
GROUP BY city;
β This groups the sales by city and shows total per group.
π Problem 2:
Now, show only those cities where total sales are above βΉ50,000.
SELECT city, SUM(sales) AS total_sales
FROM customers
GROUP BY city
HAVING total_sales > 50000;
β `HAVING filters the result after grouping.
π Problem 3:
Find departments with more than 10 active employees.
SELECT department, COUNT(*) AS emp_count
FROM employees
WHERE active = 1
GROUP BY department
HAVING emp_count > 10;
β First, we filter rows using
WHERE. Then group, then filter groups with HAVING.π‘ Use
GROUP BY to summarize, HAVING to filter those summaries.Double Tap β₯οΈ For More
β€8
β
SQL JOINS ππ
JOINS let you combine data from two or more tables based on related columns.
1οΈβ£ INNER JOIN
Returns only matching rows from both tables.
Problem: Get customers with their orders.
β Only shows customers who have orders.
2οΈβ£ LEFT JOIN (or LEFT OUTER JOIN)
Returns all rows from the left table + matching rows from the right table. If no match, fills with NULL.
Problem: Show all customers, even if they didnβt order.
β Includes customers without orders.
3οΈβ£ RIGHT JOIN
Opposite of LEFT JOIN: keeps all rows from the right table.
4οΈβ£ FULL OUTER JOIN
Returns all rows from both tables. Where thereβs no match, it shows NULL.
β Includes customers with or without orders and orders with or without customers.
5οΈβ£ SELF JOIN
Table joins with itself.
Problem: Show employees and their managers.
β Links each employee to their manager using a self join.
π‘ Quick Summary:
β’ INNER JOIN β Only matches
β’ LEFT JOIN β All from left + matches
β’ RIGHT JOIN β All from right + matches
β’ FULL OUTER JOIN β Everything
β’ SELF JOIN β Table joins itself
π¬ Tap β€οΈ for more!
JOINS let you combine data from two or more tables based on related columns.
1οΈβ£ INNER JOIN
Returns only matching rows from both tables.
Problem: Get customers with their orders.
SELECT c.name, o.order_id
FROM customers c
INNER JOIN orders o ON c.id = o.customer_id;
β Only shows customers who have orders.
2οΈβ£ LEFT JOIN (or LEFT OUTER JOIN)
Returns all rows from the left table + matching rows from the right table. If no match, fills with NULL.
Problem: Show all customers, even if they didnβt order.
SELECT c.name, o.order_id
FROM customers c
LEFT JOIN orders o ON c.id = o.customer_id;
β Includes customers without orders.
3οΈβ£ RIGHT JOIN
Opposite of LEFT JOIN: keeps all rows from the right table.
4οΈβ£ FULL OUTER JOIN
Returns all rows from both tables. Where thereβs no match, it shows NULL.
SELECT c.name, o.order_id
FROM customers c
FULL OUTER JOIN orders o ON c.id = o.customer_id;
β Includes customers with or without orders and orders with or without customers.
5οΈβ£ SELF JOIN
Table joins with itself.
Problem: Show employees and their managers.
SELECT e.name AS employee, m.name AS manager
FROM employees e
JOIN employees m ON e.manager_id = m.id;
β Links each employee to their manager using a self join.
π‘ Quick Summary:
β’ INNER JOIN β Only matches
β’ LEFT JOIN β All from left + matches
β’ RIGHT JOIN β All from right + matches
β’ FULL OUTER JOIN β Everything
β’ SELF JOIN β Table joins itself
π¬ Tap β€οΈ for more!
β€7
β
SQL Subqueries & Nested Queries π§ π
Subqueries help you write powerful queries inside other queries. They're useful when you need intermediate results.
1οΈβ£ What is a Subquery?
A subquery is a query inside
Example: Get employees who earn above average salary.
2οΈβ£ Subquery in SELECT Clause
You can use subqueries to return values in each row.
Example: Show employee names with department name.
Use when you want to filter or group temporary results.
Example: Get department-wise highest salary.
A subquery that uses a value from the outer query row.
Example: Get employees with highest salary in their department.
π‘ Real Use Cases:
β’ Filter rows based on dynamic conditions
β’ Compare values across groups
β’ Fetch related info in SELECT
π― Practice Tasks:
β’ Write a query to find 2nd highest salary
β’ Use subquery to get customers who placed more than 3 orders
β’ Create a nested query to show top-selling product per category
β Solution for Practice Tasks π
1οΈβ£ Find 2nd Highest Salary
2οΈβ£ Customers Who Placed More Than 3 Orders
You can join to get customer names:
π¬ Tap β€οΈ for more!
Subqueries help you write powerful queries inside other queries. They're useful when you need intermediate results.
1οΈβ£ What is a Subquery?
A subquery is a query inside
() that runs first and passes its result to the outer query.Example: Get employees who earn above average salary.
SELECT name, salaryβ Subquery calculates average salary β main query finds those above it.
FROM employees
WHERE salary > (SELECT AVG(salary) FROM employees);
2οΈβ£ Subquery in SELECT Clause
You can use subqueries to return values in each row.
Example: Show employee names with department name.
SELECT name,3οΈβ£ Subquery in FROM Clause
(SELECT dept_name FROM departments d WHERE d.id = e.dept_id) AS department
FROM employees e;
Use when you want to filter or group temporary results.
Example: Get department-wise highest salary.
SELECT dept_id, MAX(salary)4οΈβ£ Correlated Subquery
FROM (SELECT * FROM employees WHERE active = 1) AS active_emps
GROUP BY dept_id;
A subquery that uses a value from the outer query row.
Example: Get employees with highest salary in their department.
SELECT name, salaryβ Subquery runs for each row using outer query value.
FROM employees e
WHERE salary = (SELECT MAX(salary) FROM employees WHERE dept_id = e.dept_id);
π‘ Real Use Cases:
β’ Filter rows based on dynamic conditions
β’ Compare values across groups
β’ Fetch related info in SELECT
π― Practice Tasks:
β’ Write a query to find 2nd highest salary
β’ Use subquery to get customers who placed more than 3 orders
β’ Create a nested query to show top-selling product per category
β Solution for Practice Tasks π
1οΈβ£ Find 2nd Highest Salary
SELECT MAX(salary) AS second_highest_salaryβΆοΈ Finds the highest salary less than the max salary β gives the 2nd highest.
FROM employees
WHERE salary < (SELECT MAX(salary) FROM employees);
2οΈβ£ Customers Who Placed More Than 3 Orders
SELECT customer_idβΆοΈ Groups orders by customer and filters those with more than 3.
FROM orders
GROUP BY customer_id
HAVING COUNT(order_id) > 3;
You can join to get customer names:
SELECT name3οΈβ£ Top-Selling Product Per Category
FROM customers
WHERE id IN (
SELECT customer_id
FROM orders
GROUP BY customer_id
HAVING COUNT(order_id) > 3
);
SELECT p.name, p.category_id, p.salesβΆοΈ Correlated subquery finds the highest sales within each category.
FROM products p
WHERE p.sales = (
SELECT MAX(sales)
FROM products
WHERE category_id = p.category_id
);
π¬ Tap β€οΈ for more!
β€5π1
β
SQL CASE Statement π―
The CASE statement lets you apply conditional logic inside SQL queries β like if/else in programming.
1οΈβ£ Basic CASE Syntax
β Categorizes salaries as High, Medium, or Low.
2οΈβ£ CASE in ORDER BY
Sort based on custom logic.
β HR shows up first, then Engineering, then others.
3οΈβ£ CASE in WHERE Clause
Control filtering logic conditionally.
4οΈβ£ Nested CASE (Advanced)
π― Use CASE When You Want To:
β’ Create labels or buckets
β’ Replace multiple IF conditions
β’ Make results more readable
π Practice Tasks:
1. Add a column that shows βPassβ or βFailβ based on marks
2. Create a salary band (Low/Medium/High) using CASE
3. Use CASE to sort products as 'Electronics' first, then 'Clothing'
π¬ Tap β€οΈ for more!
The CASE statement lets you apply conditional logic inside SQL queries β like if/else in programming.
1οΈβ£ Basic CASE Syntax
SELECT name, salary,
CASE
WHEN salary > 80000 THEN 'High'
WHEN salary BETWEEN 50000 AND 80000 THEN 'Medium'
ELSE 'Low'
END AS salary_level
FROM employees;
β Categorizes salaries as High, Medium, or Low.
2οΈβ£ CASE in ORDER BY
Sort based on custom logic.
SELECT name, department
FROM employees
ORDER BY
CASE department
WHEN 'HR' THEN 1
WHEN 'Engineering' THEN 2
ELSE 3
END;
β HR shows up first, then Engineering, then others.
3οΈβ£ CASE in WHERE Clause
Control filtering logic conditionally.
SELECT *
FROM orders
WHERE status =
CASE
WHEN customer_type = 'VIP' THEN 'priority'
ELSE 'standard'
END;
4οΈβ£ Nested CASE (Advanced)
SELECT name, marks,
CASE
WHEN marks >= 90 THEN 'A'
WHEN marks >= 75 THEN
CASE WHEN marks >= 85 THEN 'B+' ELSE 'B' END
ELSE 'C'
END AS grade
FROM students;
π― Use CASE When You Want To:
β’ Create labels or buckets
β’ Replace multiple IF conditions
β’ Make results more readable
π Practice Tasks:
1. Add a column that shows βPassβ or βFailβ based on marks
2. Create a salary band (Low/Medium/High) using CASE
3. Use CASE to sort products as 'Electronics' first, then 'Clothing'
π¬ Tap β€οΈ for more!
β€4
β
SQL Programming: Handling NULL Values π οΈ
Missing data is common in databases. COALESCE() helps you fill in defaults and avoid null-related issues.
1οΈβ£ What is COALESCE?
Returns the first non-null value in a list.
β If phone is NULL, it shows βNot Providedβ.
2οΈβ£ COALESCE with Calculations
Prevent nulls from breaking math.
β If bonus is NULL, treat it as 0 to compute total.
3οΈβ£ Nested COALESCE
Use multiple fallback options.
β Checks email, then alt_email, then default text.
4οΈβ£ COALESCE in WHERE clause
Filter even when data has nulls.
π― Use COALESCE When You Want To:
β’ Replace NULLs with defaults
β’ Keep math & filters working
β’ Avoid errors in reports or dashboards
π Practice Tasks:
1. Replace nulls in city with βUnknownβ
2. Show total amount = price + tax (tax may be null)
3. Replace nulls in description with βNo Info Availableβ
β Solution for Practice Tasks π
1οΈβ£ Replace NULLs in city with 'Unknown'
2οΈβ£ Show total amount = price + tax (tax may be NULL)
3οΈβ£ Replace NULLs in description with 'No Info Available'
π¬ Tap β€οΈ for more!
Missing data is common in databases. COALESCE() helps you fill in defaults and avoid null-related issues.
1οΈβ£ What is COALESCE?
Returns the first non-null value in a list.
SELECT name, COALESCE(phone, 'Not Provided') AS contact
FROM customers;
β If phone is NULL, it shows βNot Providedβ.
2οΈβ£ COALESCE with Calculations
Prevent nulls from breaking math.
SELECT name, salary, COALESCE(bonus, 0) AS bonus,
salary + COALESCE(bonus, 0) AS total_income
FROM employees;
β If bonus is NULL, treat it as 0 to compute total.
3οΈβ£ Nested COALESCE
Use multiple fallback options.
SELECT name, COALESCE(email, alt_email, 'No Email') AS contact_email
FROM users;
β Checks email, then alt_email, then default text.
4οΈβ£ COALESCE in WHERE clause
Filter even when data has nulls.
SELECT *
FROM products
WHERE COALESCE(category, 'Uncategorized') = 'Electronics';
π― Use COALESCE When You Want To:
β’ Replace NULLs with defaults
β’ Keep math & filters working
β’ Avoid errors in reports or dashboards
π Practice Tasks:
1. Replace nulls in city with βUnknownβ
2. Show total amount = price + tax (tax may be null)
3. Replace nulls in description with βNo Info Availableβ
β Solution for Practice Tasks π
1οΈβ£ Replace NULLs in city with 'Unknown'
SELECT name, COALESCE(city, 'Unknown') AS city
FROM customers;
2οΈβ£ Show total amount = price + tax (tax may be NULL)
SELECT product_name, price, COALESCE(tax, 0) AS tax,
price + COALESCE(tax, 0) AS total_amount
FROM products;
3οΈβ£ Replace NULLs in description with 'No Info Available'
SELECT product_name, COALESCE(description, 'No Info Available') AS description
FROM products;
π¬ Tap β€οΈ for more!
β€4
β
SQL Window Functions π§ πͺ
Window functions perform calculations across rows that are related to the current row β without collapsing the result like GROUP BY.
1οΈβ£ ROW_NUMBER() β Assigns a unique row number per partition
β€ Gives ranking within each department
2οΈβ£ RANK() & DENSE_RANK() β Ranking with gaps (RANK) or without gaps (DENSE_RANK)
3οΈβ£ LAG() & LEAD() β Access previous or next row value
β€ Compare salary trends row-wise
4οΈβ£ SUM(), AVG(), COUNT() OVER() β Running totals, moving averages, etc.
5οΈβ£ NTILE(n) β Divides rows into n equal buckets
π‘ Why Use Window Functions:
β’ Perform row-wise calculations
β’ Avoid GROUP BY limitations
β’ Enable advanced analytics (ranking, trends, etc.)
π§ͺ Practice Task:
Write a query to find the top 2 earners in each department using ROW_NUMBER().
π¬ Tap β€οΈ for more!
Window functions perform calculations across rows that are related to the current row β without collapsing the result like GROUP BY.
1οΈβ£ ROW_NUMBER() β Assigns a unique row number per partition
SELECT name, department,
ROW_NUMBER() OVER (PARTITION BY department ORDER BY salary DESC) AS rank
FROM employees;
β€ Gives ranking within each department
2οΈβ£ RANK() & DENSE_RANK() β Ranking with gaps (RANK) or without gaps (DENSE_RANK)
SELECT name, salary,
RANK() OVER (ORDER BY salary DESC) AS rank
FROM employees;
3οΈβ£ LAG() & LEAD() β Access previous or next row value
SELECT name, salary,
LAG(salary) OVER (ORDER BY salary) AS prev_salary,
LEAD(salary) OVER (ORDER BY salary) AS next_salary
FROM employees;
β€ Compare salary trends row-wise
4οΈβ£ SUM(), AVG(), COUNT() OVER() β Running totals, moving averages, etc.
SELECT department, salary,
SUM(salary) OVER (PARTITION BY department) AS dept_total
FROM employees;
5οΈβ£ NTILE(n) β Divides rows into n equal buckets
SELECT name, salary,
NTILE(4) OVER (ORDER BY salary DESC) AS quartile
FROM employees;
π‘ Why Use Window Functions:
β’ Perform row-wise calculations
β’ Avoid GROUP BY limitations
β’ Enable advanced analytics (ranking, trends, etc.)
π§ͺ Practice Task:
Write a query to find the top 2 earners in each department using ROW_NUMBER().
π¬ Tap β€οΈ for more!
β€6
β
SQL Real-World Use Cases πΌπ§
SQL is the backbone of data analysis and automation in many domains. Hereβs how it powers real work:
1οΈβ£ Sales & CRM
Use Case: Sales Tracking & Pipeline Management
β’ Track sales per region, product, rep
β’ Identify top-performing leads
β’ Calculate conversion rates
SQL Task:
2οΈβ£ Finance
Use Case: Monthly Revenue and Expense Reporting
β’ Aggregate revenue by month
β’ Analyze profit margins
β’ Flag unusual transactions
SQL Task:
3οΈβ£ HR Analytics
Use Case: Employee Attrition Analysis
β’ Track tenure, exits, departments
β’ Calculate average retention
β’ Segment by age, role, or location
SQL Task:
4οΈβ£ E-commerce
Use Case: Customer Order Behavior
β’ Find most ordered products
β’ Time between repeat orders
β’ Cart abandonment patterns
SQL Task:
5οΈβ£ Healthcare
Use Case: Patient Visit Frequency
β’ Find frequent visitors
β’ Analyze doctor performance
β’ Calculate average stay duration
SQL Task:
6οΈβ£ Marketing
Use Case: Campaign Performance by Channel
β’ Track leads, clicks, conversions
β’ Compare cost-per-lead by platform
SQL Task:
π§ͺ Practice Task:
Pick a dataset (orders, users, sales)
β Write 3 queries: summary, trend, filter
β Visualize the output in Excel or Power BI
π¬ Tap β€οΈ for more!
SQL is the backbone of data analysis and automation in many domains. Hereβs how it powers real work:
1οΈβ£ Sales & CRM
Use Case: Sales Tracking & Pipeline Management
β’ Track sales per region, product, rep
β’ Identify top-performing leads
β’ Calculate conversion rates
SQL Task:
SELECT region, SUM(sales_amount)
FROM deals
GROUP BY region;
2οΈβ£ Finance
Use Case: Monthly Revenue and Expense Reporting
β’ Aggregate revenue by month
β’ Analyze profit margins
β’ Flag unusual transactions
SQL Task:
SELECT MONTH(date), SUM(revenue - expense) AS profit
FROM finance_data
GROUP BY MONTH(date);
3οΈβ£ HR Analytics
Use Case: Employee Attrition Analysis
β’ Track tenure, exits, departments
β’ Calculate average retention
β’ Segment by age, role, or location
SQL Task:
SELECT department, COUNT(*)
FROM employees
WHERE exit_date IS NOT NULL
GROUP BY department;
4οΈβ£ E-commerce
Use Case: Customer Order Behavior
β’ Find most ordered products
β’ Time between repeat orders
β’ Cart abandonment patterns
SQL Task:
SELECT customer_id, COUNT(order_id)
FROM orders
GROUP BY customer_id
HAVING COUNT(order_id) > 5;
5οΈβ£ Healthcare
Use Case: Patient Visit Frequency
β’ Find frequent visitors
β’ Analyze doctor performance
β’ Calculate average stay duration
SQL Task:
SELECT patient_id, COUNT(*) AS visits
FROM appointments
GROUP BY patient_id;
6οΈβ£ Marketing
Use Case: Campaign Performance by Channel
β’ Track leads, clicks, conversions
β’ Compare cost-per-lead by platform
SQL Task:
SELECT channel, SUM(conversions)/SUM(clicks) AS conv_rate
FROM campaign_data
GROUP BY channel;
π§ͺ Practice Task:
Pick a dataset (orders, users, sales)
β Write 3 queries: summary, trend, filter
β Visualize the output in Excel or Power BI
π¬ Tap β€οΈ for more!
β€4
β
Useful Platform to Practice SQL Programming π§ π₯οΈ
Learning SQL is just the first step β practice is what builds real skill. Here are the best platforms for hands-on SQL:
1οΈβ£ LeetCode β For Interview-Oriented SQL Practice
β’ Focus: Real interview-style problems
β’ Levels: Easy to Hard
β’ Schema + Sample Data Provided
β’ Great for: Data Analyst, Data Engineer, FAANG roles
β Tip: Start with Easy β filter by βDatabaseβ tag
β Popular Section: Database β Top 50 SQL Questions
Example Problem: βFind duplicate emails in a user tableβ β Practice filtering, GROUP BY, HAVING
2οΈβ£ HackerRank β Structured & Beginner-Friendly
β’ Focus: Step-by-step SQL track
β’ Has certification tests (SQL Basic, Intermediate)
β’ Problem sets by topic: SELECT, JOINs, Aggregations, etc.
β Tip: Follow the full SQL track
β Bonus: Company-specific challenges
Try: βRevising Aggregations β The Count Functionβ β Build confidence with small wins
3οΈβ£ Mode Analytics β Real-World SQL in Business Context
β’ Focus: Business intelligence + SQL
β’ Uses real-world datasets (e.g., e-commerce, finance)
β’ Has an in-browser SQL editor with live data
β Best for: Practicing dashboard-level queries
β Tip: Try the SQL case studies & tutorials
4οΈβ£ StrataScratch β Interview Questions from Real Companies
β’ 500+ problems from companies like Uber, Netflix, Google
β’ Split by company, difficulty, and topic
β Best for: Intermediate to advanced level
β Tip: Try βHardβ questions after doing 30β50 easy/medium
5οΈβ£ DataLemur β Short, Practical SQL Problems
β’ Crisp and to the point
β’ Good UI, fast learning
β’ Real interview-style logic
β Use when: You want fast, smart SQL drills
π How to Practice Effectively:
β’ Spend 20β30 mins/day
β’ Focus on JOINs, GROUP BY, HAVING, Subqueries
β’ Analyze problem β write β debug β re-write
β’ After solving, explain your logic out loud
π§ͺ Practice Task:
Try solving 5 SQL questions from LeetCode or HackerRank this week. Start with SELECT, WHERE, and GROUP BY.
π¬ Tap β€οΈ for more!
Learning SQL is just the first step β practice is what builds real skill. Here are the best platforms for hands-on SQL:
1οΈβ£ LeetCode β For Interview-Oriented SQL Practice
β’ Focus: Real interview-style problems
β’ Levels: Easy to Hard
β’ Schema + Sample Data Provided
β’ Great for: Data Analyst, Data Engineer, FAANG roles
β Tip: Start with Easy β filter by βDatabaseβ tag
β Popular Section: Database β Top 50 SQL Questions
Example Problem: βFind duplicate emails in a user tableβ β Practice filtering, GROUP BY, HAVING
2οΈβ£ HackerRank β Structured & Beginner-Friendly
β’ Focus: Step-by-step SQL track
β’ Has certification tests (SQL Basic, Intermediate)
β’ Problem sets by topic: SELECT, JOINs, Aggregations, etc.
β Tip: Follow the full SQL track
β Bonus: Company-specific challenges
Try: βRevising Aggregations β The Count Functionβ β Build confidence with small wins
3οΈβ£ Mode Analytics β Real-World SQL in Business Context
β’ Focus: Business intelligence + SQL
β’ Uses real-world datasets (e.g., e-commerce, finance)
β’ Has an in-browser SQL editor with live data
β Best for: Practicing dashboard-level queries
β Tip: Try the SQL case studies & tutorials
4οΈβ£ StrataScratch β Interview Questions from Real Companies
β’ 500+ problems from companies like Uber, Netflix, Google
β’ Split by company, difficulty, and topic
β Best for: Intermediate to advanced level
β Tip: Try βHardβ questions after doing 30β50 easy/medium
5οΈβ£ DataLemur β Short, Practical SQL Problems
β’ Crisp and to the point
β’ Good UI, fast learning
β’ Real interview-style logic
β Use when: You want fast, smart SQL drills
π How to Practice Effectively:
β’ Spend 20β30 mins/day
β’ Focus on JOINs, GROUP BY, HAVING, Subqueries
β’ Analyze problem β write β debug β re-write
β’ After solving, explain your logic out loud
π§ͺ Practice Task:
Try solving 5 SQL questions from LeetCode or HackerRank this week. Start with SELECT, WHERE, and GROUP BY.
π¬ Tap β€οΈ for more!
β€7
β
Data Analytics Roadmap for Freshers in 2025 ππ
1οΈβ£ Understand What a Data Analyst Does
π Analyze data, find insights, create dashboards, support business decisions.
2οΈβ£ Start with Excel
π Learn:
β Basic formulas
β Charts & Pivot Tables
β Data cleaning
π‘ Excel is still the #1 tool in many companies.
3οΈβ£ Learn SQL
π§© SQL helps you pull and analyze data from databases.
Start with:
β SELECT, WHERE, JOIN, GROUP BY
π οΈ Practice on platforms like W3Schools or Mode Analytics.
4οΈβ£ Pick a Programming Language
π Start with Python (easier) or R
β Learn pandas, matplotlib, numpy
β Do small projects (e.g. analyze sales data)
5οΈβ£ Data Visualization Tools
π Learn:
β Power BI or Tableau
β Build simple dashboards
π‘ Start with free versions or YouTube tutorials.
6οΈβ£ Practice with Real Data
π Use sites like Kaggle or Data.gov
β Clean, analyze, visualize
β Try small case studies (sales report, customer trends)
7οΈβ£ Create a Portfolio
π» Share projects on:
β GitHub
β Notion or a simple website
π Add visuals + brief explanations of your insights.
8οΈβ£ Improve Soft Skills
π£οΈ Focus on:
β Presenting data in simple words
β Asking good questions
β Thinking critically about patterns
9οΈβ£ Certifications to Stand Out
π Try:
β Google Data Analytics (Coursera)
β IBM Data Analyst
β LinkedIn Learning basics
π Apply for Internships & Entry Jobs
π― Titles to look for:
β Data Analyst (Intern)
β Junior Analyst
β Business Analyst
π¬ React β€οΈ for more!
1οΈβ£ Understand What a Data Analyst Does
π Analyze data, find insights, create dashboards, support business decisions.
2οΈβ£ Start with Excel
π Learn:
β Basic formulas
β Charts & Pivot Tables
β Data cleaning
π‘ Excel is still the #1 tool in many companies.
3οΈβ£ Learn SQL
π§© SQL helps you pull and analyze data from databases.
Start with:
β SELECT, WHERE, JOIN, GROUP BY
π οΈ Practice on platforms like W3Schools or Mode Analytics.
4οΈβ£ Pick a Programming Language
π Start with Python (easier) or R
β Learn pandas, matplotlib, numpy
β Do small projects (e.g. analyze sales data)
5οΈβ£ Data Visualization Tools
π Learn:
β Power BI or Tableau
β Build simple dashboards
π‘ Start with free versions or YouTube tutorials.
6οΈβ£ Practice with Real Data
π Use sites like Kaggle or Data.gov
β Clean, analyze, visualize
β Try small case studies (sales report, customer trends)
7οΈβ£ Create a Portfolio
π» Share projects on:
β GitHub
β Notion or a simple website
π Add visuals + brief explanations of your insights.
8οΈβ£ Improve Soft Skills
π£οΈ Focus on:
β Presenting data in simple words
β Asking good questions
β Thinking critically about patterns
9οΈβ£ Certifications to Stand Out
π Try:
β Google Data Analytics (Coursera)
β IBM Data Analyst
β LinkedIn Learning basics
π Apply for Internships & Entry Jobs
π― Titles to look for:
β Data Analyst (Intern)
β Junior Analyst
β Business Analyst
π¬ React β€οΈ for more!
β€9
β
How to Build a Job-Ready Data Analytics Portfolio πΌπ
1οΈβ£ Pick Solid Datasets
β’ Public: Kaggle, UCI ML Repo, data.gov
β’ Business-like: e-commerce, churn, marketing spend, HR attrition
β’ Size: 5kβ200k rows, relatively clean
2οΈβ£ Create 3 Signature Projects
β’ SQL: Customer Cohort & Retention (joins, window functions)
β’ BI: Executive Sales Dashboard (Power BI/Tableau, drill-through, DAX/calculated fields)
β’ Python: Marketing ROI & Attribution (pandas, seaborn, A/B test basics)
3οΈβ£ Tell a Story, Not Just Charts
β’ Problem β Approach β Insight β Action
β’ Add one business recommendation per insight
4οΈβ£ Document Like a Pro
β’ README: problem, data source, methods, results, next steps
β’ Screenshots or GIFs of dashboards
β’ Repo structure: /data, /notebooks, /sql, /reports
5οΈβ£ Show Measurable Impact
β’ βReduced reporting time by 70% with automated Power BI pipelineβ
β’ βIdentified 12% churn segment with a retention playbookβ
6οΈβ£ Make It Easy to Review
β’ Share live dashboards (Publish to Web), short Loom/YouTube walkthrough
β’ Include SQL snippets
β’ Pin top 3 projects on GitHub and LinkedIn Featured
7οΈβ£ Iterate With Feedback
β’ Post drafts on LinkedIn, ask βWhat would you improve?β
β’ Apply suggestions, track updates in a CHANGELOG
π― Goal: 3 projects, 3 stories, 3 measurable outcomes.
π¬ Double Tap β€οΈ For More!
1οΈβ£ Pick Solid Datasets
β’ Public: Kaggle, UCI ML Repo, data.gov
β’ Business-like: e-commerce, churn, marketing spend, HR attrition
β’ Size: 5kβ200k rows, relatively clean
2οΈβ£ Create 3 Signature Projects
β’ SQL: Customer Cohort & Retention (joins, window functions)
β’ BI: Executive Sales Dashboard (Power BI/Tableau, drill-through, DAX/calculated fields)
β’ Python: Marketing ROI & Attribution (pandas, seaborn, A/B test basics)
3οΈβ£ Tell a Story, Not Just Charts
β’ Problem β Approach β Insight β Action
β’ Add one business recommendation per insight
4οΈβ£ Document Like a Pro
β’ README: problem, data source, methods, results, next steps
β’ Screenshots or GIFs of dashboards
β’ Repo structure: /data, /notebooks, /sql, /reports
5οΈβ£ Show Measurable Impact
β’ βReduced reporting time by 70% with automated Power BI pipelineβ
β’ βIdentified 12% churn segment with a retention playbookβ
6οΈβ£ Make It Easy to Review
β’ Share live dashboards (Publish to Web), short Loom/YouTube walkthrough
β’ Include SQL snippets
β’ Pin top 3 projects on GitHub and LinkedIn Featured
7οΈβ£ Iterate With Feedback
β’ Post drafts on LinkedIn, ask βWhat would you improve?β
β’ Apply suggestions, track updates in a CHANGELOG
π― Goal: 3 projects, 3 stories, 3 measurable outcomes.
π¬ Double Tap β€οΈ For More!
β€3
Core SQL Interview Questions. With answers
1 What is SQL
β’ SQL stands for Structured Query Language
β’ You use it to read and manage data in relational databases
β’ Used in MySQL, PostgreSQL, SQL Server, Oracle
2 What is an RDBMS
β’ Relational Database Management System
β’ Stores data in tables with rows and columns
β’ Uses keys to link tables
β’ Example. Customer table linked to Orders table using customer_id
3 What is a table
β’ Structured storage for data
β’ Rows are records
β’ Columns are attributes
β’ Example. One row equals one customer
4 What is a primary key
β’ Uniquely identifies each row
β’ Cannot be NULL
β’ No duplicate values
β’ Example. user_id in users table
5 What is a foreign key
β’ Links one table to another
β’ Refers to a primary key in another table
β’ Allows duplicate values
β’ Example. user_id in orders table
6 Difference between primary key and foreign key
β’ Primary key ensures uniqueness
β’ Foreign key ensures relationship
β’ One table can have one primary key
β’ One table can have multiple foreign keys
7 What is NULL
β’ Represents missing or unknown value
β’ Not equal to zero or empty string
β’ Use IS NULL or IS NOT NULL to check
8 What are constraints
β’ Rules applied on columns
β’ Maintain data quality
β’ Common constraints
β NOT NULL
β UNIQUE
β PRIMARY KEY
β FOREIGN KEY
β CHECK
9 What are data types
β’ Define type of data stored
β’ Common types
β INT for numbers
β VARCHAR for text
β DATE for dates
β FLOAT or DECIMAL for decimals
10 Interview tip you must remember
β’ Always explain with a small example
β’ Speak logic before syntax
β’ Keep answers short and direct
Double Tap β€οΈ For More
1 What is SQL
β’ SQL stands for Structured Query Language
β’ You use it to read and manage data in relational databases
β’ Used in MySQL, PostgreSQL, SQL Server, Oracle
2 What is an RDBMS
β’ Relational Database Management System
β’ Stores data in tables with rows and columns
β’ Uses keys to link tables
β’ Example. Customer table linked to Orders table using customer_id
3 What is a table
β’ Structured storage for data
β’ Rows are records
β’ Columns are attributes
β’ Example. One row equals one customer
4 What is a primary key
β’ Uniquely identifies each row
β’ Cannot be NULL
β’ No duplicate values
β’ Example. user_id in users table
5 What is a foreign key
β’ Links one table to another
β’ Refers to a primary key in another table
β’ Allows duplicate values
β’ Example. user_id in orders table
6 Difference between primary key and foreign key
β’ Primary key ensures uniqueness
β’ Foreign key ensures relationship
β’ One table can have one primary key
β’ One table can have multiple foreign keys
7 What is NULL
β’ Represents missing or unknown value
β’ Not equal to zero or empty string
β’ Use IS NULL or IS NOT NULL to check
8 What are constraints
β’ Rules applied on columns
β’ Maintain data quality
β’ Common constraints
β NOT NULL
β UNIQUE
β PRIMARY KEY
β FOREIGN KEY
β CHECK
9 What are data types
β’ Define type of data stored
β’ Common types
β INT for numbers
β VARCHAR for text
β DATE for dates
β FLOAT or DECIMAL for decimals
10 Interview tip you must remember
β’ Always explain with a small example
β’ Speak logic before syntax
β’ Keep answers short and direct
Double Tap β€οΈ For More
β€11