A curated collection of SQL interview questions, solutions, explanations, and patterns commonly asked in top tech companies.
This repository is designed for:
- Software Engineering Interviews
- Data Analyst Interviews
- Data Scientist Interviews
- Business Intelligence Roles
- Product Analytics Roles
- FAANG & Top Product Companies
The goal is not just to memorize queries, but to understand the underlying concepts and develop strong SQL problem-solving skills.
SQL/
│
├── 01-Basics/
├── 02-Filtering-Sorting/
├── 03-Aggregations/
├── 04-Joins/
├── 05-Subqueries/
├── 06-CTEs/
├── 07-Window-Functions/
├── 08-Date-Time/
├── 09-String-Functions/
├── 10-Case-Statements/
├── 11-Advanced-SQL/
├── 12-Interview-Questions/
├── 13-Real-World-Case-Studies/
└── Resources/
- SELECT
- WHERE
- ORDER BY
- LIMIT
- DISTINCT
- Aliases
- Basic Functions
- GROUP BY
- HAVING
- JOINS
- UNION
- CASE WHEN
- Subqueries
- CTEs
- Window Functions
- Ranking Functions
- Recursive CTEs
- Query Optimization
- Indexing
- Execution Plans
- Data Warehousing Concepts
Common Questions:
- Second Highest Salary
- Department Wise Salary
- Top N Employees
- Monthly Revenue
Key Concepts:
GROUP BY
HAVING
COUNT()
SUM()
AVG()
MIN()
MAX()Types:
INNER JOIN
LEFT JOIN
RIGHT JOIN
FULL OUTER JOIN
SELF JOIN
CROSS JOINFrequently Asked:
- Customers Without Orders
- Employee Manager Relationship
- Product Sales Analysis
Must Know:
ROW_NUMBER()
RANK()
DENSE_RANK()
LEAD()
LAG()
FIRST_VALUE()
LAST_VALUE()FAANG Favorite Questions:
- Nth Highest Salary
- Consecutive Logins
- Running Total
- User Retention
WITH cte AS (
SELECT *
FROM employees
)
SELECT *
FROM cte;Used For:
- Readability
- Recursive Problems
- Complex Analytics
Frequently Tested:
- DAU / MAU
- Cohort Analysis
- Retention Analysis
- Monthly Revenue Growth
Functions:
DATE_ADD()
DATEDIFF()
EXTRACT()
DATE_TRUNC()
CURRENT_DATETopics:
SUBSTRING()
CONCAT()
TRIM()
REPLACE()
LENGTH()
UPPER()
LOWER()- SELECT
- WHERE
- ORDER BY
- GROUP BY
- HAVING
- CASE WHEN
- JOINS
- UNION
- Subqueries
- CTEs
- Window Functions
- Recursive CTEs
- Query Optimization
- Indexing
- Execution Plans
- Data Modeling
- Analytics SQL
| Topic | Difficulty |
|---|---|
| Second Highest Salary | Easy |
| Nth Highest Salary | Medium |
| Duplicate Records | Easy |
| Consecutive Logins | Medium |
| Running Total | Medium |
| Department Top Earners | Medium |
| Customer Retention | Hard |
| Cohort Analysis | Hard |
| Sessionization | Hard |
| Funnel Analysis | Hard |
- Window Functions
- Analytics SQL
- Product Metrics
- User Retention
- Funnels
- Event Analysis
- Complex Joins
- Aggregations
- Business Metrics
- Time Series Analysis
- Geospatial Data
- Marketplace Metrics
- Booking Analytics
- Ranking Problems
- Experiment Analysis
- Basics
- Filtering & Sorting
- Aggregations
- Joins
- Subqueries
- CTEs
- Window Functions
- Advanced Analytics
- Mock Interviews
- Learn the concept.
- Solve the problem without looking at the solution.
- Optimize the query.
- Compare alternative approaches.
- Review execution complexity.
- Revisit after one week.
Contributions are welcome.
If you'd like to improve explanations, add optimized solutions, or include additional interview questions, feel free to open a Pull Request.
If this repository helped you:
⭐ Star the repository
🍴 Fork the repository
📢 Share it with fellow interview candidates