β
SQL Subquery Practice Questions with Answers β Part 2 π§ ποΈ
π Q1. Find employees earning more than the average salary of their department.
ποΈ Table: "employees(emp_id, name, department_id, salary)"
β Answer:
π Q2. Get customers who never placed any order.
ποΈ Tables: "customers(customer_id, name)", "orders(order_id, customer_id)"
β Answer:
π Q3. Find the second highest salary from employees.
ποΈ Table: "employees(emp_id, name, salary)"
β Answer:
π Q4. List products priced higher than the average product price.
ποΈ Table: "products(product_id, product_name, price)"
β Answer:
π Q5. Find employees who work in the same department as 'John'.
ποΈ Table: "employees(emp_id, name, department_id)"
β Answer:
Double Tap β₯οΈ For More
π Q1. Find employees earning more than the average salary of their department.
ποΈ Table: "employees(emp_id, name, department_id, salary)"
β Answer:
SELECT name, department_id, salary
FROM employees e1
WHERE salary > (
SELECT AVG(salary)
FROM employees e2
WHERE e1.department_id = e2.department_id
);
π Q2. Get customers who never placed any order.
ποΈ Tables: "customers(customer_id, name)", "orders(order_id, customer_id)"
β Answer:
SELECT customer_id, name
FROM customers
WHERE customer_id NOT IN (
SELECT customer_id
FROM orders
);
π Q3. Find the second highest salary from employees.
ποΈ Table: "employees(emp_id, name, salary)"
β Answer:
SELECT MAX(salary) AS second_highest_salary
FROM employees
WHERE salary < (
SELECT MAX(salary)
FROM employees
);
π Q4. List products priced higher than the average product price.
ποΈ Table: "products(product_id, product_name, price)"
β Answer:
SELECT product_name, price
FROM products
WHERE price > (
SELECT AVG(price)
FROM products
);
π Q5. Find employees who work in the same department as 'John'.
ποΈ Table: "employees(emp_id, name, department_id)"
β Answer:
SELECT name, department_id
FROM employees
WHERE department_id = (
SELECT department_id
FROM employees
WHERE name = 'John'
);
Double Tap β₯οΈ For More
β€11π2
β
SQL Interview Roadmap β Step-by-Step Guide to Crack Any SQL Round πΌπ
Whether you're applying for Data Analyst, BI, or Data Engineer roles β SQL rounds are must-clear. Here's your focused roadmap:
1οΈβ£ Core SQL Concepts
πΉ Understand RDBMS, tables, keys, schemas
πΉ Data types,
π§ Interview Tip: Be able to explain
2οΈβ£ Basic Queries
πΉ
π§ Practice: Filter and sort data by multiple columns.
3οΈβ£ Joins β Very Frequently Asked!
πΉ
π§ Interview Tip: Explain the difference with examples.
π§ͺ Practice: Write queries using joins across 2β3 tables.
4οΈβ£ Aggregations & GROUP BY
πΉ
π§ Common Question: Total sales per category where total > X.
5οΈβ£ Window Functions
πΉ
π§ Interview Favorite: Top N per group, previous row comparison.
6οΈβ£ Subqueries & CTEs
πΉ Write queries inside
π§ Use Case: Filtering on aggregated data, simplifying logic.
7οΈβ£ CASE Statements
πΉ Add logic directly in
π§ Example: Categorize users based on spend or activity.
8οΈβ£ Data Cleaning & Transformation
πΉ Handle
π§ Real-world Task: Clean user input data.
9οΈβ£ Query Optimization Basics
πΉ Understand indexing, query plan, performance tips
π§ Interview Tip: Difference between
π Real-World Scenarios
π§ Must Practice:
β’ Sales funnel
β’ Retention cohort
β’ Churn rate
β’ Revenue by channel
β’ Daily active users
π§ͺ Practice Platforms
β’ LeetCode (EasyβHard SQL)
β’ StrataScratch (Real business cases)
β’ Mode Analytics (SQL + Visualization)
β’ HackerRank SQL (MCQs + Coding)
πΌ Final Tip:
Explain why your query works, not just what it does. Speak your logic clearly.
π¬ Tap β€οΈ for more!
Whether you're applying for Data Analyst, BI, or Data Engineer roles β SQL rounds are must-clear. Here's your focused roadmap:
1οΈβ£ Core SQL Concepts
πΉ Understand RDBMS, tables, keys, schemas
πΉ Data types,
NULLs, constraints π§ Interview Tip: Be able to explain
Primary vs Foreign Key.2οΈβ£ Basic Queries
πΉ
SELECT, FROM, WHERE, ORDER BY, LIMIT π§ Practice: Filter and sort data by multiple columns.
3οΈβ£ Joins β Very Frequently Asked!
πΉ
INNER, LEFT, RIGHT, FULL OUTER JOIN π§ Interview Tip: Explain the difference with examples.
π§ͺ Practice: Write queries using joins across 2β3 tables.
4οΈβ£ Aggregations & GROUP BY
πΉ
COUNT, SUM, AVG, MIN, MAX, HAVING π§ Common Question: Total sales per category where total > X.
5οΈβ£ Window Functions
πΉ
ROW_NUMBER(), RANK(), DENSE_RANK(), LAG(), LEAD() π§ Interview Favorite: Top N per group, previous row comparison.
6οΈβ£ Subqueries & CTEs
πΉ Write queries inside
WHERE, FROM, and using WITH π§ Use Case: Filtering on aggregated data, simplifying logic.
7οΈβ£ CASE Statements
πΉ Add logic directly in
SELECT π§ Example: Categorize users based on spend or activity.
8οΈβ£ Data Cleaning & Transformation
πΉ Handle
NULLs, format dates, string manipulation (TRIM, SUBSTRING) π§ Real-world Task: Clean user input data.
9οΈβ£ Query Optimization Basics
πΉ Understand indexing, query plan, performance tips
π§ Interview Tip: Difference between
WHERE and HAVING.π Real-World Scenarios
π§ Must Practice:
β’ Sales funnel
β’ Retention cohort
β’ Churn rate
β’ Revenue by channel
β’ Daily active users
π§ͺ Practice Platforms
β’ LeetCode (EasyβHard SQL)
β’ StrataScratch (Real business cases)
β’ Mode Analytics (SQL + Visualization)
β’ HackerRank SQL (MCQs + Coding)
πΌ Final Tip:
Explain why your query works, not just what it does. Speak your logic clearly.
π¬ Tap β€οΈ for more!
β€14π1
β
SQL Mistakes Beginners Should Avoid π§ π»
1οΈβ£ Using SELECT *
β’ Pulls unused columns
β’ Slows queries
β’ Breaks when schema changes
β’ Use only required columns
2οΈβ£ Ignoring NULL Values
β’ NULL breaks calculations
β’ COUNT(column) skips NULL
β’ Use
3οΈβ£ Wrong JOIN Type
β’ INNER instead of LEFT
β’ Data silently disappears
β’ Always ask: Do you need unmatched rows?
4οΈβ£ Missing JOIN Conditions
β’ Creates cartesian product
β’ Rows explode
β’ Always join on keys
5οΈβ£ Filtering After JOIN Instead of Before
β’ Processes more rows than needed
β’ Slower performance
β’ Filter early using
6οΈβ£ Using WHERE Instead of HAVING
β’
β’
β’ Aggregates fail without
7οΈβ£ Not Using Indexes
β’ Full table scans
β’ Slow dashboards
β’ Index columns used in
8οΈβ£ Relying on ORDER BY in Subqueries
β’ Order not guaranteed
β’ Results change
β’ Use
9οΈβ£ Mixing Data Types
β’ Implicit conversions
β’ Index not used
β’ Match column data types
π No Query Validation
β’ Results look right but are wrong
β’ Always cross-check counts and totals
π§ Practice Task
β’ Rewrite one query
β’ Remove
β’ Add proper
β’ Handle
β’ Compare result count
SQL Resources: https://whatsapp.com/channel/0029VanC5rODzgT6TiTGoa1v
β€οΈ Double Tap For More
1οΈβ£ Using SELECT *
β’ Pulls unused columns
β’ Slows queries
β’ Breaks when schema changes
β’ Use only required columns
2οΈβ£ Ignoring NULL Values
β’ NULL breaks calculations
β’ COUNT(column) skips NULL
β’ Use
COALESCE or IS NULL checks3οΈβ£ Wrong JOIN Type
β’ INNER instead of LEFT
β’ Data silently disappears
β’ Always ask: Do you need unmatched rows?
4οΈβ£ Missing JOIN Conditions
β’ Creates cartesian product
β’ Rows explode
β’ Always join on keys
5οΈβ£ Filtering After JOIN Instead of Before
β’ Processes more rows than needed
β’ Slower performance
β’ Filter early using
WHERE or subqueries6οΈβ£ Using WHERE Instead of HAVING
β’
WHERE filters rowsβ’
HAVING filters groupsβ’ Aggregates fail without
HAVING7οΈβ£ Not Using Indexes
β’ Full table scans
β’ Slow dashboards
β’ Index columns used in
JOIN, WHERE, ORDER BY8οΈβ£ Relying on ORDER BY in Subqueries
β’ Order not guaranteed
β’ Results change
β’ Use
ORDER BY only in final query9οΈβ£ Mixing Data Types
β’ Implicit conversions
β’ Index not used
β’ Match column data types
π No Query Validation
β’ Results look right but are wrong
β’ Always cross-check counts and totals
π§ Practice Task
β’ Rewrite one query
β’ Remove
SELECT *β’ Add proper
JOINβ’ Handle
NULLsβ’ Compare result count
SQL Resources: https://whatsapp.com/channel/0029VanC5rODzgT6TiTGoa1v
β€οΈ Double Tap For More
β€7
Best practices for writing SQL queries:
Join for more: https://t.me/learndataanalysis
1- Write SQL keywords in capital letters.
2- Use table aliases with columns when you are joining multiple tables.
3- Never use select *, always mention list of columns in select clause.
4- Add useful comments wherever you write complex logic. Avoid too many comments.
5- Use joins instead of subqueries when possible for better performance.
6- Create CTEs instead of multiple sub queries , it will make your query easy to read.
7- Join tables using JOIN keywords instead of writing join condition in where clause for better readability.
8- Never use order by in sub queries , It will unnecessary increase runtime.
9- If you know there are no duplicates in 2 tables, use UNION ALL instead of UNION for better performance.
Join for more: https://t.me/learndataanalysis
1- Write SQL keywords in capital letters.
2- Use table aliases with columns when you are joining multiple tables.
3- Never use select *, always mention list of columns in select clause.
4- Add useful comments wherever you write complex logic. Avoid too many comments.
5- Use joins instead of subqueries when possible for better performance.
6- Create CTEs instead of multiple sub queries , it will make your query easy to read.
7- Join tables using JOIN keywords instead of writing join condition in where clause for better readability.
8- Never use order by in sub queries , It will unnecessary increase runtime.
9- If you know there are no duplicates in 2 tables, use UNION ALL instead of UNION for better performance.
β€7
SQL Interview Questions with Answers Part-1: βοΈ
1. What is SQL?
SQL (Structured Query Language) is a standardized programming language designed to manage and manipulate relational databases. It allows you to query, insert, update, and delete data, as well as create and modify schema objects like tables and views.
2. Differentiate between SQL and NoSQL databases.
SQL databases are relational, table-based, and use structured query language with fixed schemas, ideal for complex queries and transactions. NoSQL databases are non-relational, can be document, key-value, graph, or column-oriented, and are schema-flexible, designed for scalability and handling unstructured data.
3. What are the different types of SQL commands?
β¦ DDL (Data Definition Language): CREATE, ALTER, DROP (define and modify structure)
β¦ DML (Data Manipulation Language): SELECT, INSERT, UPDATE, DELETE (data operations)
β¦ DCL (Data Control Language): GRANT, REVOKE (permission control)
β¦ TCL (Transaction Control Language): COMMIT, ROLLBACK, SAVEPOINT (transaction management)
4. Explain the difference between WHERE and HAVING clauses.
β¦
β¦
5. Write a SQL query to find the second highest salary in a table.
Using a subquery:
Or using DENSE_RANK():
6. What is a JOIN? Explain different types of JOINs.
A JOIN combines rows from two or more tables based on a related column:
β¦ INNER JOIN: returns matching rows from both tables.
β¦ LEFT JOIN (LEFT OUTER JOIN): all rows from the left table, matched rows from right.
β¦ RIGHT JOIN (RIGHT OUTER JOIN): all rows from right table, matched rows from left.
β¦ FULL JOIN (FULL OUTER JOIN): all rows when thereβs a match in either table.
β¦ CROSS JOIN: Cartesian product of both tables.
7. How do you optimize slow-performing SQL queries?
β¦ Use indexes appropriately to speed up lookups.
β¦ Avoid SELECT *; only select necessary columns.
β¦ Use joins carefully; filter early with WHERE clauses.
β¦ Analyze execution plans to identify bottlenecks.
β¦ Avoid unnecessary subqueries; use EXISTS or JOINs.
β¦ Limit result sets with pagination if dealing with large datasets.
8. What is a primary key? What is a foreign key?
β¦ Primary Key: A unique identifier for records in a table; it cannot be NULL.
β¦ Foreign Key: A field that creates a link between two tables by referring to the primary key in another table, enforcing referential integrity.
9. What are indexes? Explain clustered and non-clustered indexes.
β¦ Indexes speed up data retrieval by providing quick lookups.
β¦ Clustered Index: Sorts and stores the actual data rows in the table based on the key; a table can have only one clustered index.
β¦ Non-Clustered Index: Creates a separate structure that points to the data rows; tables can have multiple non-clustered indexes.
10. Write a SQL query to fetch the top 5 records from a table.
In SQL Server and PostgreSQL:
In SQL Server (older syntax):
React β₯οΈ for Part 2
1. What is SQL?
SQL (Structured Query Language) is a standardized programming language designed to manage and manipulate relational databases. It allows you to query, insert, update, and delete data, as well as create and modify schema objects like tables and views.
2. Differentiate between SQL and NoSQL databases.
SQL databases are relational, table-based, and use structured query language with fixed schemas, ideal for complex queries and transactions. NoSQL databases are non-relational, can be document, key-value, graph, or column-oriented, and are schema-flexible, designed for scalability and handling unstructured data.
3. What are the different types of SQL commands?
β¦ DDL (Data Definition Language): CREATE, ALTER, DROP (define and modify structure)
β¦ DML (Data Manipulation Language): SELECT, INSERT, UPDATE, DELETE (data operations)
β¦ DCL (Data Control Language): GRANT, REVOKE (permission control)
β¦ TCL (Transaction Control Language): COMMIT, ROLLBACK, SAVEPOINT (transaction management)
4. Explain the difference between WHERE and HAVING clauses.
β¦
WHERE filters rows before grouping (used with SELECT, UPDATE).β¦
HAVING filters groups after aggregation (used with GROUP BY), e.g., filtering aggregated results like sums or counts.5. Write a SQL query to find the second highest salary in a table.
Using a subquery:
SELECT MAX(salary) FROM employees
WHERE salary < (SELECT MAX(salary) FROM employees);
Or using DENSE_RANK():
SELECT salary FROM (
SELECT salary, DENSE_RANK() OVER (ORDER BY salary DESC) as rnk
FROM employees) t
WHERE rnk = 2;
6. What is a JOIN? Explain different types of JOINs.
A JOIN combines rows from two or more tables based on a related column:
β¦ INNER JOIN: returns matching rows from both tables.
β¦ LEFT JOIN (LEFT OUTER JOIN): all rows from the left table, matched rows from right.
β¦ RIGHT JOIN (RIGHT OUTER JOIN): all rows from right table, matched rows from left.
β¦ FULL JOIN (FULL OUTER JOIN): all rows when thereβs a match in either table.
β¦ CROSS JOIN: Cartesian product of both tables.
7. How do you optimize slow-performing SQL queries?
β¦ Use indexes appropriately to speed up lookups.
β¦ Avoid SELECT *; only select necessary columns.
β¦ Use joins carefully; filter early with WHERE clauses.
β¦ Analyze execution plans to identify bottlenecks.
β¦ Avoid unnecessary subqueries; use EXISTS or JOINs.
β¦ Limit result sets with pagination if dealing with large datasets.
8. What is a primary key? What is a foreign key?
β¦ Primary Key: A unique identifier for records in a table; it cannot be NULL.
β¦ Foreign Key: A field that creates a link between two tables by referring to the primary key in another table, enforcing referential integrity.
9. What are indexes? Explain clustered and non-clustered indexes.
β¦ Indexes speed up data retrieval by providing quick lookups.
β¦ Clustered Index: Sorts and stores the actual data rows in the table based on the key; a table can have only one clustered index.
β¦ Non-Clustered Index: Creates a separate structure that points to the data rows; tables can have multiple non-clustered indexes.
10. Write a SQL query to fetch the top 5 records from a table.
In SQL Server and PostgreSQL:
SELECT * FROM table_name
ORDER BY some_column DESC
LIMIT 5;
In SQL Server (older syntax):
SELECT TOP 5 * FROM table_name
ORDER BY some_column DESC;
React β₯οΈ for Part 2
β€16π1
β
SQL Mistakes Beginners Should Avoid π§ π»
1οΈβ£ Using SELECT *
β’ Pulls unused columns
β’ Slows queries
β’ Breaks when schema changes
β’ Use only required columns
2οΈβ£ Ignoring NULL Values
β’ NULL breaks calculations
β’ COUNT(column) skips NULL
β’ Use
3οΈβ£ Wrong JOIN Type
β’ INNER instead of LEFT
β’ Data silently disappears
β’ Always ask: Do you need unmatched rows?
4οΈβ£ Missing JOIN Conditions
β’ Creates cartesian product
β’ Rows explode
β’ Always join on keys
5οΈβ£ Filtering After JOIN Instead of Before
β’ Processes more rows than needed
β’ Slower performance
β’ Filter early using
6οΈβ£ Using WHERE Instead of HAVING
β’
β’
β’ Aggregates fail without
7οΈβ£ Not Using Indexes
β’ Full table scans
β’ Slow dashboards
β’ Index columns used in
8οΈβ£ Relying on ORDER BY in Subqueries
β’ Order not guaranteed
β’ Results change
β’ Use
9οΈβ£ Mixing Data Types
β’ Implicit conversions
β’ Index not used
β’ Match column data types
π No Query Validation
β’ Results look right but are wrong
β’ Always cross-check counts and totals
π§ Practice Task
β’ Rewrite one query
β’ Remove
β’ Add proper
β’ Handle
β’ Compare result count
SQL Resources: https://whatsapp.com/channel/0029VanC5rODzgT6TiTGoa1v
β€οΈ Double Tap For More
1οΈβ£ Using SELECT *
β’ Pulls unused columns
β’ Slows queries
β’ Breaks when schema changes
β’ Use only required columns
2οΈβ£ Ignoring NULL Values
β’ NULL breaks calculations
β’ COUNT(column) skips NULL
β’ Use
COALESCE or IS NULL checks3οΈβ£ Wrong JOIN Type
β’ INNER instead of LEFT
β’ Data silently disappears
β’ Always ask: Do you need unmatched rows?
4οΈβ£ Missing JOIN Conditions
β’ Creates cartesian product
β’ Rows explode
β’ Always join on keys
5οΈβ£ Filtering After JOIN Instead of Before
β’ Processes more rows than needed
β’ Slower performance
β’ Filter early using
WHERE or subqueries6οΈβ£ Using WHERE Instead of HAVING
β’
WHERE filters rowsβ’
HAVING filters groupsβ’ Aggregates fail without
HAVING7οΈβ£ Not Using Indexes
β’ Full table scans
β’ Slow dashboards
β’ Index columns used in
JOIN, WHERE, ORDER BY8οΈβ£ Relying on ORDER BY in Subqueries
β’ Order not guaranteed
β’ Results change
β’ Use
ORDER BY only in final query9οΈβ£ Mixing Data Types
β’ Implicit conversions
β’ Index not used
β’ Match column data types
π No Query Validation
β’ Results look right but are wrong
β’ Always cross-check counts and totals
π§ Practice Task
β’ Rewrite one query
β’ Remove
SELECT *β’ Add proper
JOINβ’ Handle
NULLsβ’ Compare result count
SQL Resources: https://whatsapp.com/channel/0029VanC5rODzgT6TiTGoa1v
β€οΈ Double Tap For More
β€9
β
π€ AβZ of SQL Commands ποΈπ»β‘
A β ALTER
Modify an existing table structure (add/modify/drop columns).
B β BEGIN
Start a transaction block.
C β CREATE
Create database objects like tables, views, indexes.
D β DELETE
Remove records from a table.
E β EXISTS
Check if a subquery returns any rows.
F β FETCH
Retrieve rows from a cursor.
G β GRANT
Give privileges to users.
H β HAVING
Filter aggregated results (used with GROUP BY).
I β INSERT
Add new records into a table.
J β JOIN
Combine rows from two or more tables.
K β KEY (PRIMARY KEY / FOREIGN KEY)
Define constraints for uniqueness and relationships.
L β LIMIT
Restrict number of rows returned (MySQL/PostgreSQL).
M β MERGE
Insert/update data conditionally (mainly in SQL Server/Oracle).
N β NULL
Represents missing or unknown data.
O β ORDER BY
Sort query results.
P β PROCEDURE
Stored program in the database.
Q β QUERY
Request for data (general SQL statement).
R β ROLLBACK
Undo changes in a transaction.
S β SELECT
Retrieve data from tables.
T β TRUNCATE
Remove all records from a table quickly.
U β UPDATE
Modify existing records.
V β VIEW
Virtual table based on a query.
W β WHERE
Filter records based on conditions.
X β XML PATH
Generate XML output (mainly SQL Server).
Y β YEAR()
Extract year from a date.
Z β ZONE (AT TIME ZONE)
Convert datetime to specific time zone.
β€οΈ Double Tap for More
A β ALTER
Modify an existing table structure (add/modify/drop columns).
B β BEGIN
Start a transaction block.
C β CREATE
Create database objects like tables, views, indexes.
D β DELETE
Remove records from a table.
E β EXISTS
Check if a subquery returns any rows.
F β FETCH
Retrieve rows from a cursor.
G β GRANT
Give privileges to users.
H β HAVING
Filter aggregated results (used with GROUP BY).
I β INSERT
Add new records into a table.
J β JOIN
Combine rows from two or more tables.
K β KEY (PRIMARY KEY / FOREIGN KEY)
Define constraints for uniqueness and relationships.
L β LIMIT
Restrict number of rows returned (MySQL/PostgreSQL).
M β MERGE
Insert/update data conditionally (mainly in SQL Server/Oracle).
N β NULL
Represents missing or unknown data.
O β ORDER BY
Sort query results.
P β PROCEDURE
Stored program in the database.
Q β QUERY
Request for data (general SQL statement).
R β ROLLBACK
Undo changes in a transaction.
S β SELECT
Retrieve data from tables.
T β TRUNCATE
Remove all records from a table quickly.
U β UPDATE
Modify existing records.
V β VIEW
Virtual table based on a query.
W β WHERE
Filter records based on conditions.
X β XML PATH
Generate XML output (mainly SQL Server).
Y β YEAR()
Extract year from a date.
Z β ZONE (AT TIME ZONE)
Convert datetime to specific time zone.
β€οΈ Double Tap for More
β€19
β
Complete Roadmap to Learn SQL in 2026 π
π SQL powers 80% of data analytics jobs.
π πΉ SQL FOUNDATIONS
π― 1οΈβ£ SELECT Basics (Week 1)
- SELECT \*, specific columns
- FROM tables
- WHERE filters
- ORDER BY, LIMIT
π’ Practice: Query your first dataset today
π 2οΈβ£ Filtering Mastery
- Comparison operators (=, >, BETWEEN)
- Logical: AND, OR, IN
- Pattern matching: LIKE, %
- NULL handling
π 3οΈβ£ Aggregate Power
- COUNT(\*), SUM, AVG, MIN/MAX
- GROUP BY essentials
- HAVING vs WHERE
- DISTINCT counts
π π₯ SQL CORE SKILLS
π 4οΈβ£ JOINS (Most Important β)
- INNER JOIN (must-know)
- LEFT, RIGHT, FULL JOIN
- Multi-table joins
- Self-joins
β‘ 5οΈβ£ Subqueries & CTEs
- Subqueries in WHERE/FROM
- WITH clause (CTEs)
- Multiple CTE chains
- EXISTS/NOT EXISTS
π 6οΈβ£ Window Functions (Game-Changer β)
- ROW_NUMBER(), RANK()
- PARTITION BY magic
- LAG/LEAD (trends)
- Running totals
π¨ π ADVANCED SQL MASTERY
β° 7οΈβ£ Date & Time
- DATEADD, DATEDIFF
- DATE_TRUNC, EXTRACT
- Date filtering patterns
- Cohort analysis
π€ 8οΈβ£ String Functions
- CONCAT, SUBSTRING
- TRIM, UPPER/LOWER
- LENGTH, REPLACE
π€ 9οΈβ£ CASE Statements
- Simple vs searched CASE
- Nested logic
- Policy calculations
βοΈ π§ PERFORMANCE & JOBS
π 1οΈβ£0οΈβ£ Indexing Basics
- CREATE INDEX strategies
- EXPLAIN query plans
- Composite indexes
π» 1οΈβ£1οΈβ£ Practice Platforms
- LeetCode SQL (50 problems)
- HackerRank SQL
- StrataScratch (real cases)
- DDIA datasets
π± 1οΈβ£2οΈβ£ Modern SQL Tools
- pgAdmin (PostgreSQL)
- DBeaver (universal)
- BigQuery Sandbox (free)
- dbt + SQL
πΌ β‘ INTERVIEW READY
π― 1οΈβ£3οΈβ£ Top Interview Questions
- Find 2nd highest salary
- Nth highest records
- Duplicate detection
- Window ranking
π 1οΈβ£4οΈβ£ Real Projects
- Sales dashboard queries
- Customer segmentation
- Inventory optimization
- Build GitHub portfolio
π¨ β ESSENTIAL SQL TOOLS 2026
- PostgreSQL (free, powerful)
- MySQL Workbench
- BigQuery (cloud-native)
- Snowflake (trial)
1οΈβ£5οΈβ£ FREE RESOURCES
π SQLBolt (interactive)
π Mode Analytics Tutorial
β‘ LeetCode SQL 50
π₯ DataCamp SQL (free tier)
π W3schools
Double Tap β₯οΈ For Detailed Explanation
π SQL powers 80% of data analytics jobs.
π πΉ SQL FOUNDATIONS
π― 1οΈβ£ SELECT Basics (Week 1)
- SELECT \*, specific columns
- FROM tables
- WHERE filters
- ORDER BY, LIMIT
π’ Practice: Query your first dataset today
π 2οΈβ£ Filtering Mastery
- Comparison operators (=, >, BETWEEN)
- Logical: AND, OR, IN
- Pattern matching: LIKE, %
- NULL handling
π 3οΈβ£ Aggregate Power
- COUNT(\*), SUM, AVG, MIN/MAX
- GROUP BY essentials
- HAVING vs WHERE
- DISTINCT counts
π π₯ SQL CORE SKILLS
π 4οΈβ£ JOINS (Most Important β)
- INNER JOIN (must-know)
- LEFT, RIGHT, FULL JOIN
- Multi-table joins
- Self-joins
β‘ 5οΈβ£ Subqueries & CTEs
- Subqueries in WHERE/FROM
- WITH clause (CTEs)
- Multiple CTE chains
- EXISTS/NOT EXISTS
π 6οΈβ£ Window Functions (Game-Changer β)
- ROW_NUMBER(), RANK()
- PARTITION BY magic
- LAG/LEAD (trends)
- Running totals
π¨ π ADVANCED SQL MASTERY
β° 7οΈβ£ Date & Time
- DATEADD, DATEDIFF
- DATE_TRUNC, EXTRACT
- Date filtering patterns
- Cohort analysis
π€ 8οΈβ£ String Functions
- CONCAT, SUBSTRING
- TRIM, UPPER/LOWER
- LENGTH, REPLACE
π€ 9οΈβ£ CASE Statements
- Simple vs searched CASE
- Nested logic
- Policy calculations
βοΈ π§ PERFORMANCE & JOBS
π 1οΈβ£0οΈβ£ Indexing Basics
- CREATE INDEX strategies
- EXPLAIN query plans
- Composite indexes
π» 1οΈβ£1οΈβ£ Practice Platforms
- LeetCode SQL (50 problems)
- HackerRank SQL
- StrataScratch (real cases)
- DDIA datasets
π± 1οΈβ£2οΈβ£ Modern SQL Tools
- pgAdmin (PostgreSQL)
- DBeaver (universal)
- BigQuery Sandbox (free)
- dbt + SQL
πΌ β‘ INTERVIEW READY
π― 1οΈβ£3οΈβ£ Top Interview Questions
- Find 2nd highest salary
- Nth highest records
- Duplicate detection
- Window ranking
π 1οΈβ£4οΈβ£ Real Projects
- Sales dashboard queries
- Customer segmentation
- Inventory optimization
- Build GitHub portfolio
π¨ β ESSENTIAL SQL TOOLS 2026
- PostgreSQL (free, powerful)
- MySQL Workbench
- BigQuery (cloud-native)
- Snowflake (trial)
1οΈβ£5οΈβ£ FREE RESOURCES
π SQLBolt (interactive)
π Mode Analytics Tutorial
β‘ LeetCode SQL 50
π₯ DataCamp SQL (free tier)
π W3schools
Double Tap β₯οΈ For Detailed Explanation
β€11
If I had to start learning data analyst all over again, I'd follow this:
1- Learn SQL:
---- Joins (Inner, Left, Full outer and Self)
---- Aggregate Functions (COUNT, SUM, AVG, MIN, MAX)
---- Group by and Having clause
---- CTE and Subquery
---- Windows Function (Rank, Dense Rank, Row number, Lead, Lag etc)
2- Learn Excel:
---- Mathematical (COUNT, SUM, AVG, MIN, MAX, etc)
---- Logical Functions (IF, AND, OR, NOT)
---- Lookup and Reference (VLookup, INDEX, MATCH etc)
---- Pivot Table, Filters, Slicers
3- Learn BI Tools:
---- Data Integration and ETL (Extract, Transform, Load)
---- Report Generation
---- Data Exploration and Ad-hoc Analysis
---- Dashboard Creation
4- Learn Python (Pandas) Optional:
---- Data Structures, Data Cleaning and Preparation
---- Data Manipulation
---- Merging and Joining Data (Merging and joining DataFrames -similar to SQL joins)
---- Data Visualization (Basic plotting using Matplotlib and Seaborn)
Hope this helps you π
1- Learn SQL:
---- Joins (Inner, Left, Full outer and Self)
---- Aggregate Functions (COUNT, SUM, AVG, MIN, MAX)
---- Group by and Having clause
---- CTE and Subquery
---- Windows Function (Rank, Dense Rank, Row number, Lead, Lag etc)
2- Learn Excel:
---- Mathematical (COUNT, SUM, AVG, MIN, MAX, etc)
---- Logical Functions (IF, AND, OR, NOT)
---- Lookup and Reference (VLookup, INDEX, MATCH etc)
---- Pivot Table, Filters, Slicers
3- Learn BI Tools:
---- Data Integration and ETL (Extract, Transform, Load)
---- Report Generation
---- Data Exploration and Ad-hoc Analysis
---- Dashboard Creation
4- Learn Python (Pandas) Optional:
---- Data Structures, Data Cleaning and Preparation
---- Data Manipulation
---- Merging and Joining Data (Merging and joining DataFrames -similar to SQL joins)
---- Data Visualization (Basic plotting using Matplotlib and Seaborn)
Hope this helps you π
β€3
π― SQL Fundamentals Part-1: SELECT Basics
SELECT is the most used SQL command, used to retrieve data from a database.
Think of SQL like asking questions to a database. SELECT = asking what data you want.
β What is SELECT in SQL?
SELECT statement retrieves data from one or more tables in a database.
π Basic Syntax
How SQL executes:
1. Finds table (FROM)
2. Applies filter (WHERE)
3. Returns selected columns (SELECT)
4. Sorts results (ORDER BY)
5. Limits rows (LIMIT)
πΉ 1. SELECT All Columns (SELECT *)
Used to retrieve every column from a table.
π Returns complete table data.
π When to use:
β Exploring new dataset
β Checking table structure
β Quick testing
β οΈ Avoid in production: Slow on large tables, fetches unnecessary data.
πΉ 2. SELECT Specific Columns
Best practice β retrieve only required data.
π Returns only selected columns.
π‘ Why important:
β Faster queries
β Better performance
β Cleaner results
πΉ 3. FROM Clause (Data Source)
Specifies where data comes from.
π SQL reads data from customers table.
πΉ 4. WHERE Clause (Filtering Data)
Used to filter rows based on conditions.
Examples:
- Filter by value:
- Filter by text:
πΉ 5. ORDER BY (Sorting Results)
Sorts query results.
Examples:
- Ascending:
- Descending:
πΉ 6. LIMIT (Control Output Rows)
Restricts number of returned rows.
π Returns first 5 records.
β SQL Query Execution Order
1. FROM
2. WHERE
3. SELECT
4. ORDER BY
5. LIMIT
π§ Real-World Example
Business question: "Show top 10 highest paid employees."
π Mini Practice Tasks
β Task 1: Get all records from customers.
β Task 2: Show only customer name and city.
β Task 3: Find employees with salary > 40000.
β Task 4: Show top 3 highest priced products.
Double Tap β₯οΈ For Part-2
SELECT is the most used SQL command, used to retrieve data from a database.
Think of SQL like asking questions to a database. SELECT = asking what data you want.
β What is SELECT in SQL?
SELECT statement retrieves data from one or more tables in a database.
π Basic Syntax
SELECT column_name
FROM table_name;
How SQL executes:
1. Finds table (FROM)
2. Applies filter (WHERE)
3. Returns selected columns (SELECT)
4. Sorts results (ORDER BY)
5. Limits rows (LIMIT)
πΉ 1. SELECT All Columns (SELECT *)
Used to retrieve every column from a table.
SELECT *
FROM employees;
π Returns complete table data.
π When to use:
β Exploring new dataset
β Checking table structure
β Quick testing
β οΈ Avoid in production: Slow on large tables, fetches unnecessary data.
πΉ 2. SELECT Specific Columns
Best practice β retrieve only required data.
SELECT name, salary
FROM employees;
π Returns only selected columns.
π‘ Why important:
β Faster queries
β Better performance
β Cleaner results
πΉ 3. FROM Clause (Data Source)
Specifies where data comes from.
SELECT name
FROM customers;
π SQL reads data from customers table.
πΉ 4. WHERE Clause (Filtering Data)
Used to filter rows based on conditions.
SELECT column
FROM table
WHERE condition;
Examples:
- Filter by value:
SELECT * FROM employees WHERE salary > 50000;- Filter by text:
SELECT * FROM employees WHERE city = 'Mumbai';πΉ 5. ORDER BY (Sorting Results)
Sorts query results.
SELECT column
FROM table
ORDER BY column ASC | DESC;
Examples:
- Ascending:
SELECT name, salary FROM employees ORDER BY salary ASC;- Descending:
SELECT name, salary FROM employees ORDER BY salary DESC;πΉ 6. LIMIT (Control Output Rows)
Restricts number of returned rows.
SELECT *
FROM employees
LIMIT 5;
π Returns first 5 records.
β SQL Query Execution Order
1. FROM
2. WHERE
3. SELECT
4. ORDER BY
5. LIMIT
π§ Real-World Example
Business question: "Show top 10 highest paid employees."
SELECT name, salary
FROM employees
ORDER BY salary DESC
LIMIT 10;
π Mini Practice Tasks
β Task 1: Get all records from customers.
β Task 2: Show only customer name and city.
β Task 3: Find employees with salary > 40000.
β Task 4: Show top 3 highest priced products.
Double Tap β₯οΈ For Part-2
β€15π€1
π SQL Fundamentals Part-2: Filtering
After learning SELECT basics, the next step is learning how to filter data.
π In real-world data analysis, you rarely need full data β you filter specific rows.
Filtering = extracting only relevant data from a table.
β What is Filtering in SQL?
Filtering is done using the WHERE clause.
It allows you to:
β Get specific records
β Apply conditions
β Clean data
β Extract business insights
πΉ 1. Comparison Operators
Used to compare values.
Operator Meaning
β’ = Equal
β’ > Greater than
β’ < Less than
β’ >= Greater than or equal
β’ <= Less than or equal
β’ != or <> Not equal
β Examples
β’ Equal to
SELECT * FROM employees WHERE city = 'Pune';
β’ Greater than
SELECT * FROM employees WHERE salary > 50000;
β’ Not equal
SELECT * FROM employees WHERE department != 'HR';
π‘ Most commonly used in dashboards reporting.
πΉ 2. Logical Operators (AND, OR, NOT)
Used to combine multiple conditions.
β AND β Both conditions must be true
SELECT * FROM employees WHERE salary > 50000 AND city = 'Mumbai';
π Returns employees with: salary > 50000 AND located in Mumbai
β OR β Any condition can be true
SELECT * FROM employees WHERE city = 'Delhi' OR city = 'Pune';
π Returns employees from either city.
β NOT β Reverse condition
SELECT * FROM employees WHERE NOT department = 'Sales';
π Excludes Sales department.
πΉ 3. BETWEEN (Range Filtering)
Used to filter values within a range.
Syntax
SELECT * FROM table WHERE column BETWEEN value1 AND value2;
β Example
SELECT * FROM employees WHERE salary BETWEEN 30000 AND 70000;
π Includes boundary values.
πΉ 4. IN Operator (Multiple Values Shortcut)
Better alternative to multiple OR conditions.
β Without IN
WHERE city = 'Pune' OR city = 'Delhi' OR city = 'Mumbai'
β With IN
SELECT * FROM employees WHERE city IN ('Pune','Delhi','Mumbai');
π Cleaner and faster.
πΉ 5. LIKE β Pattern Matching
Used for searching text patterns.
β Wildcards
Symbol Meaning
β’ % Any number of characters
β’ _ Single character
β Starts with "A"
SELECT * FROM customers WHERE name LIKE 'A%';
β Ends with "n"
WHERE name LIKE '%n';
β Contains "an"
WHERE name LIKE '%an%';
Used heavily in search features.
πΉ 6. NULL Handling (Very Important β)
NULL means:
π Missing / unknown value
π Not zero
π Not empty
β Wrong
WHERE salary = NULL
β Correct
SELECT * FROM employees WHERE salary IS NULL;
Check non-null values
WHERE salary IS NOT NULL;
π‘ Very common interview question.
β Order of Filtering Execution
SQL processes filtering after reading table:
FROM β WHERE β SELECT β ORDER BY β LIMIT
π§ Real-World Data Analyst Examples
Q. Find customers from Pune
SELECT * FROM customers WHERE city = 'Pune';
Q. Find high-paying jobs in IT department
SELECT * FROM employees WHERE salary > 80000 AND department = 'IT';
Q. Find names starting with "R"
SELECT * FROM employees WHERE name LIKE 'R%';
Used daily in business analytics.
π Mini Practice Tasks
β Q1
Find employees whose salary is greater than 60000.
β Q2
Find customers from Pune or Mumbai.
β Q3
Find products priced between 100 and 500.
β Q4
Find employees whose name starts with "S".
β Q5
Find records where email is missing (NULL).
β Double Tap β₯οΈ For More
After learning SELECT basics, the next step is learning how to filter data.
π In real-world data analysis, you rarely need full data β you filter specific rows.
Filtering = extracting only relevant data from a table.
β What is Filtering in SQL?
Filtering is done using the WHERE clause.
It allows you to:
β Get specific records
β Apply conditions
β Clean data
β Extract business insights
πΉ 1. Comparison Operators
Used to compare values.
Operator Meaning
β’ = Equal
β’ > Greater than
β’ < Less than
β’ >= Greater than or equal
β’ <= Less than or equal
β’ != or <> Not equal
β Examples
β’ Equal to
SELECT * FROM employees WHERE city = 'Pune';
β’ Greater than
SELECT * FROM employees WHERE salary > 50000;
β’ Not equal
SELECT * FROM employees WHERE department != 'HR';
π‘ Most commonly used in dashboards reporting.
πΉ 2. Logical Operators (AND, OR, NOT)
Used to combine multiple conditions.
β AND β Both conditions must be true
SELECT * FROM employees WHERE salary > 50000 AND city = 'Mumbai';
π Returns employees with: salary > 50000 AND located in Mumbai
β OR β Any condition can be true
SELECT * FROM employees WHERE city = 'Delhi' OR city = 'Pune';
π Returns employees from either city.
β NOT β Reverse condition
SELECT * FROM employees WHERE NOT department = 'Sales';
π Excludes Sales department.
πΉ 3. BETWEEN (Range Filtering)
Used to filter values within a range.
Syntax
SELECT * FROM table WHERE column BETWEEN value1 AND value2;
β Example
SELECT * FROM employees WHERE salary BETWEEN 30000 AND 70000;
π Includes boundary values.
πΉ 4. IN Operator (Multiple Values Shortcut)
Better alternative to multiple OR conditions.
β Without IN
WHERE city = 'Pune' OR city = 'Delhi' OR city = 'Mumbai'
β With IN
SELECT * FROM employees WHERE city IN ('Pune','Delhi','Mumbai');
π Cleaner and faster.
πΉ 5. LIKE β Pattern Matching
Used for searching text patterns.
β Wildcards
Symbol Meaning
β’ % Any number of characters
β’ _ Single character
β Starts with "A"
SELECT * FROM customers WHERE name LIKE 'A%';
β Ends with "n"
WHERE name LIKE '%n';
β Contains "an"
WHERE name LIKE '%an%';
Used heavily in search features.
πΉ 6. NULL Handling (Very Important β)
NULL means:
π Missing / unknown value
π Not zero
π Not empty
β Wrong
WHERE salary = NULL
β Correct
SELECT * FROM employees WHERE salary IS NULL;
Check non-null values
WHERE salary IS NOT NULL;
π‘ Very common interview question.
β Order of Filtering Execution
SQL processes filtering after reading table:
FROM β WHERE β SELECT β ORDER BY β LIMIT
π§ Real-World Data Analyst Examples
Q. Find customers from Pune
SELECT * FROM customers WHERE city = 'Pune';
Q. Find high-paying jobs in IT department
SELECT * FROM employees WHERE salary > 80000 AND department = 'IT';
Q. Find names starting with "R"
SELECT * FROM employees WHERE name LIKE 'R%';
Used daily in business analytics.
π Mini Practice Tasks
β Q1
Find employees whose salary is greater than 60000.
β Q2
Find customers from Pune or Mumbai.
β Q3
Find products priced between 100 and 500.
β Q4
Find employees whose name starts with "S".
β Q5
Find records where email is missing (NULL).
β Double Tap β₯οΈ For More
β€8