0% found this document useful (0 votes)
5 views

SQL questions

The document outlines various SQL-related tasks, interview questions, and frameworks for data analysis, including combining tables, identifying duplicate emails, and analyzing employee salaries. It also includes a series of SQL interview questions that cover topics such as joins, window functions, and data retrieval techniques. Additionally, there are sections dedicated to Power BI and Python questions relevant to data analysis roles.

Uploaded by

nagpureaarushi
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

SQL questions

The document outlines various SQL-related tasks, interview questions, and frameworks for data analysis, including combining tables, identifying duplicate emails, and analyzing employee salaries. It also includes a series of SQL interview questions that cover topics such as joins, window functions, and data retrieval techniques. Additionally, there are sections dedicated to Power BI and Python questions relevant to data analysis roles.

Uploaded by

nagpureaarushi
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 25

1. Combine two tables: https://lnkd.

in/dumdCXC7
2. Employees earning > managers: https://Inkd.in/dKqcFmzY
3. Duplicate emails: https://lnkd.in/dJSYfs89
4. Customers who never order : https://lnkd.in/dPZPAKFf
5. Delete duplicate emails: https://lnkd.in/dEKnD9s3
6. Rising temperature: https://lnkd.in/dyZvVYvP
7. Employee bonus: https://Inkd.in/d9iTXt-V
8. Find customer referee : https://lnkd.in/d5cXjXdb
10. Big countries: https://lnkd.in/dAnS54qK
11. Classes more than 5 students : https://lnkd.in/dfrUiutd
12. Sales person: https://lnkd.in/dwRnf5Df
13. Triangle judgement: https://lnkd.in/dwzD-hFn
14. Biggest single number: https://lnkd.in/d4F5zHDs
15. Not boring movies: https://lnkd.in/d5w8_z65
16. Swap salary: https://lnkd.in/dnbCtecM
18. Product sales analysis 1: https://lnkd.in/dRj3EBuK
19. Project employees 1: https://lnkd.in/dvGHsbKQ
20. Sales analysis III : https://lnkd.in/d_y_rxPh

Common SQL question framework for interviews:


1- Top N products by sales, Top N products within each category, Ton N employees by salaries, etc.
2- Year-over-year growth, YOY growth for each category, Products with higher sales than the
previous month, etc.

3- Running sales over months, rolling N months sales, within each category etc.

4- Pivot rows to columns, eg: year wise sales for each category in separate columns, etc

5- Number of records after different kinds of joins.

Deloitte:

1. Tell us about yourself and your current job responsibilities.


2. Can you share some challenges you encountered in your recent project involving Power BI
dashboards, and how did you resolve them?
3. What distinguishes a KPI (Key Performance Indicator) from a dimension?
4. Write a SQL query to find the third highest salary from an employee table with the following
columns: EID, ESalary.
5. Create a SQL procedure using ESalary as a parameter that selects all EIDs from the Employee
table where ESalary is less than 50,000.
6. For the Employee table (with columns EID and ESalary), retrieve all EIDs with odd salaries and join
this with another table, empdetails (with columns EID and EDOB), to obtain EDOB.
7. How would you use the LEAD or LAG function in SQL to compare week-over-week data?
8. Can you explain how you would create a DAX measure in Power BI to calculate the year-over-year
growth for a specific metric?
9. Identify a unique chart type in Power BI that differs from standard charts and explain its purpose.
10. Describe how you would implement a time intelligence feature in Power BI to analyze sales
trends over different time periods.

1. Explain the differences between OLTP and OLAP systems.


2. What are the ACID properties in a database transaction?
3. Define normalization and its various normal forms.
4. What is denormalization, and when would you use it?
5. Describe the different types of SQL joins and their use cases.
6. What is a subquery, and how does it differ from a correlated subquery?
7. Explain the concept of indexing and its impact on query performance.
8. What are common causes of SQL injection, and how can they be prevented?
9. Differentiate between clustered and non-clustered indexes.
10. What is a stored procedure, and how does it differ from a function?
11. Explain the purpose of a view in SQL and its advantages.
12. What are window functions, and how do they differ from aggregate functions?
13. Define a common table expression (CTE) and its typical use cases.
14. How do you handle NULL values in SQL queries?
15. What is the difference between the WHERE and HAVING clauses?
16. Explain the concept of a transaction and its importance in databases.
17. What are triggers, and when would you use them?
18. Describe the differences between UNION and UNION ALL.
19. What is a primary key, and how does it differ from a unique key?
20. Explain the concept of referential integrity in databases.
21. What are the differences between DELETE, TRUNCATE, and DROP commands?
22. How do you optimize a slow-running query?
23. What is a materialized view, and how does it differ from a regular view?
24. Explain the concept of database normalization and its benefits.
25. What are the differences between SQL and NoSQL databases?
26. How do you implement error handling in SQL?
27. What is the purpose of the GROUP BY clause in SQL?
28. Explain the concept of a foreign key and its role in relational databases.
29. What are the differences between INNER JOIN and OUTER JOIN?
30. How do you ensure data integrity in a relational database?

1. Amazon
Link: https://lnkd.in/dC64SAXX

2. Google
Link: https://lnkd.in/dmex67dV

3. Goldman Sachs
Link: https://lnkd.in/dKn2EUPv

4. Microsoft
Link: https://lnkd.in/dUWRbi-8

5. Uber
Link: https://lnkd.in/dvt8RpGg

Basic Data Retrieval:


hashtag
#Question: "Write an SQL query to fetch the top 10 highest earning employees from the 'Employee'
table."
hashtag
#Purpose: Tests basic SELECT and ORDER BY clauses.

Aggregations and Groupings:


hashtag
#Question: "How would you write a query to find the average salary in each department of a
company?"
hashtag
#Purpose: Assesses knowledge of GROUP BY and aggregate functions like AVG().

hashtag
#Complex Joins:
hashtag
#Question: "You need to produce a report showing all customers who have not made any purchases
in the last year. How would you structure your SQL query?"
hashtag
#Purpose: Tests ability to perform LEFT JOINs and use conditions to filter data.

Subqueries and Nested Queries:


hashtag
#Question: "Can you write a query that selects the names of employees who earn more than the
average salary in their respective departments?"
hashtag
#Purpose: Evaluates understanding of subqueries and the use of aggregate functions within them.

Data Cleaning:
hashtag
#Question: "How would you identify and update or remove records that contain null values in critical
fields in the database?"
hashtag
#Purpose: Tests skills in data integrity checks and UPDATE/DELETE operations.

Window Functions:
hashtag
#Question: "Write a SQL query to rank employees within each department based on their salary."
hashtag
#Purpose: Assesses knowledge of window functions like RANK() or DENSE_RANK().

EXL Data Analyst Interview Experience:


CTC - 15 LPA

SQL Questions

1. You have a table Transactions with columns TransactionID, CustomerID, Date, and Amount. Write
a query to calculate the cumulative revenue per customer for each month in the last year.
2. A table Production contains columns PlantID, Date, and Output. Write a query to identify the plants
that consistently exceeded their daily average output for at least 20 days in a given month.
3. In a table EmployeeAttendance with columns EmployeeID, Date, and Status (values: ‘Present’,
‘Absent’), write a query to find employees with the highest consecutive absences in the last quarter.
4. What are the pros and cons of using indexes in SQL, and when would you avoid using them?
5. Explain the differences between window functions and aggregate functions with examples.

Python Questions

6. Write a Python script to merge multiple CSV files from a directory into a single file and perform
basic data cleaning.
7. Given a list of dictionaries, write a Python program to group the data by a specific key and
calculate summary statistics for the grouped data.
8. Explain the difference between a list, a tuple, and a dictionary in Python, and provide examples of
their usage.
9. Write a Python function to automate the generation of monthly reports from a dataset stored in an
Excel file.

Power BI Questions

10. How would you create a dashboard in Power BI to track the operational efficiency of production
plants?
11. Explain how you would handle a situation where the data source refresh in Power BI is causing
delays.
12. What is the difference between row-level security and role-level security in Power BI?
13. How would you use Power BI to visualize trends and outliers in daily sales data?
14. Discuss how you would create a calculated measure to show YoY (Year-over-Year) growth in
Power BI.

General Questions

15. Share an example where your data-driven insights helped solve a business problem or improve a
process.
16. How do you prioritize tasks and manage deadlines in a high-pressure environment?
17. Why do you want to join EXL, and how do you see your expertise aligning with their vision?

🔹SQL56: ESPN https://lnkd.in/gD8uBP_Q

🔹SQL55: Amazon https://lnkd.in/gHAc4sfU

🔹SQL54: Meta https://lnkd.in/ghBxrPEM

🔹SQL53: Doordash https://lnkd.in/gGNUWph7

🔹SQL52: Tesla https://lnkd.in/g2Jv7zhV

🔹SQL51: Amazon https://lnkd.in/gfVcyVyf

🔹SQL50: Meta https://lnkd.in/g-JE53BS


🔹SQL49: Goldman Sachs https://lnkd.in/gHZuAJbf

🔹SQL48: Amazon, Doordash, Bosch https://lnkd.in/g35zi6cW

🔹SQL47: Expedia, Airbnb, Tripadvisor https://lnkd.in/gaStqh4P

🔹SQL46: Deloitte, EY, TCS https://lnkd.in/g8qbc_v4

🔹SQL45: Visa https://lnkd.in/g3SDNxFp

🔹SQL44: Amazon https://lnkd.in/g4V9iY5G

🔹SQL43: Apple https://shorturl.at/55yDH

🔹SQL42: Microsoft https://shorturl.at/WLafx

🔹SQL41: Meta https://shorturl.at/C44m6

🔹SQL40: Walmart https://shorturl.at/0vqWQ

🔹SQL39: Amazon https://shorturl.at/JuwvD

🔹SQL38: Airbnb https://shorturl.at/ojYlx

🔹SQL37: Netflix https://shorturl.at/i0KHh

🔹SQL36: Uber https://shorturl.at/DiAol

🔹SQL35: X https://shorturl.at/rcVxq

🔹SQL34: Google, Expedia, Airbnb https://rb.gy/91rdbj

🔹SQL33: Google https://rb.gy/hdqknb

🔹SQL32: Accenture https://shorturl.at/yysrt

🔹SQL31: Spotify https://shorturl.at/X3rqN

🔹SQL30: Amazon https://shorturl.at/4Hs79

🔹SQL29: Cisco https://shorturl.at/WDxNR

🔹SQL28: Meta, Salesforce http://surl.li/ltyjkr

🔹SQL27: GoldmanSachs, Deloitte https://shorturl.at/33YeI


🔹SQL26: Linkedln https://lnkd.in/ga65v3QN

🔹SQL25: American Express https://lnkd.in/gF_mmRsN

🔹SQL24: Amazon https://shorturl.at/OebkH

🔹SQL23: Oracle https://shorturl.at/R9cZD

🔹SQL22: Walmart, Paypal https://shorturl.at/Z1bX0

🔹SQL21: Microsoft https://shorturl.at/r2FiB

🔹SQL20: Apple, Microsoft https://lnkd.in/g8kU4vep

🔹SQL19: Walmart https://lnkd.in/gzqv3f-R

🔹SQL18: Amazon, Doordash https://lnkd.in/gKgdfP6c

🔹SQL17: Uber https://lnkd.in/gQphbD4M

🔹SQL16: JP Morgan https://lnkd.in/gWVVPrjP

🔹SQL15: Google https://lnkd.in/g_vzRNwq

🔹SQL14: Amazon, Salesforce https://lnkd.in/gAz4phAS

🔹SQL13: Expedia, Airbnb https://lnkd.in/gUfzuZbk

🔹SQL12: Linkedln, Dropbox https://lnkd.in/g9tZsSmJ

🔹SQL11: Nvidia, Microsoft https://lnkd.in/gGPkEV35

🔹SQL10: Amazon https://lnkd.in/gs-3sX6V

🔹SQL9: Netflix https://lnkd.in/guCXi8k9

🔹SQL8: Tesla https://lnkd.in/gJwdGBtN

🔹SQL7: IBM https://lnkd.in/gqx8mFNs

🔹SQL6: Airbnb https://lnkd.in/gep8Td4w

🔹SQL5: Microsoft https://lnkd.in/gXPMAD48

🔹SQL4: Uber https://lnkd.in/g6h5Nj5Q


🔹SQL3: Google https://lnkd.in/gmHfrmWE

🔹SQL2: Amazon https://lnkd.in/gW63hRvU

🔹SQL1: Meta/Facebook https://lnkd.in/gWZ_WD8m

Medium Level:
1 How do you identify duplicate records in a table?
1️⃣
2️⃣How can you delete duplicates while keeping just one entry?
3️⃣What's the difference between UNION and UNION ALL?
4️⃣When should you use RANK, ROW_NUMBER, and DENSE_RANK?
5️⃣How do you find records in one table that don’t exist in another?
6️⃣How do you retrieve the second-highest salary for each department?
7️⃣How do you find employees earning more than their manager?
8️⃣What’s the key difference between INNER JOIN and LEFT JOIN?
9️⃣How would you swap gender values (M ↔ F) in a table using SQL?
🔟 How do different types of joins impact the number of records in the output?

1️⃣How do you identify duplicate records in a table?


2️⃣How can you delete duplicates while keeping just one entry?
3️⃣What's the difference between UNION and UNION ALL?
4️⃣When should you use RANK, ROW_NUMBER, and DENSE_RANK?
5️⃣How do you find records in one table that don’t exist in another?
6️⃣How do you retrieve the second-highest salary for each department?
7️⃣How do you find employees earning more than their manager?
8️⃣What’s the key difference between INNER JOIN and LEFT JOIN?
9️⃣How would you swap gender values (M ↔ F) in a table using SQL?
🔟 How do different types of joins impact the number of records in the output?
1️⃣1️⃣How do you retrieve the nth highest salary from a table?
1️⃣2️⃣What’s the difference between HAVING and WHERE in SQL?
1️⃣3️⃣How do you pivot rows into columns in SQL?
1️⃣4️⃣How do you calculate a running total in SQL?
1️⃣5️⃣How would you identify and handle orphan records in a database?
1️⃣6️⃣What’s the difference between DELETE, TRUNCATE, and DROP?
1️⃣7️⃣How do you find the longest consecutive sequence of values in a column?
1️⃣8️⃣What is a self-join, and when would you use it?
1️⃣9️⃣How do you find the earliest and latest records for each group in a table?
How do you optimize SQL queries for better performance?
22️⃣00️⃣

➤ 𝗪𝗶𝗻𝗱𝗼𝘄 𝗙𝘂𝗻𝗰𝘁𝗶𝗼𝗻𝘀

1. Find the cumulative sum of sales for each employee.


2. Rank employees based on their sales within their department.
3. Calculate a running total of orders by order date.
4. Identify the top three salaries in each department.
5. Compute the difference between the current and previous month's sales.

➤ 𝗖𝗼𝗺𝗺𝗼𝗻 𝗧𝗮𝗯𝗹𝗲 𝗘𝘅𝗽𝗿𝗲𝘀𝘀𝗶𝗼𝗻𝘀 (𝗖𝗧𝗘)

1. Write a recursive CTE to generate a sequence of numbers from 1 to 100.


2. Use a CTE to find employees who directly and indirectly report to a specific manager.
3. Calculate the factorial of a number using a recursive CTE.
4. Flatten a hierarchical organization chart using a CTE.
5. Use a CTE to calculate year-over-year growth in sales.

➤ 𝗝𝗼𝗶𝗻𝘀 (𝗜𝗻𝗻𝗲𝗿, 𝗢𝘂𝘁𝗲𝗿, 𝗖𝗿𝗼𝘀𝘀, 𝗦𝗲𝗹𝗳)

1. Retrieve a list of customers who have placed orders (Inner Join).


2. Find employees who have not been assigned to any projects (Left Join).
3. Get a list of projects without assigned employees (Right Join).
4. Generate all possible pairs of products (Cross Join).
5. Match employees to themselves to find pairs from the same department (Self Join).

➤ 𝗦𝘂𝗯𝗾𝘂𝗲𝗿𝗶𝗲𝘀

1. Find employees earning more than the average salary in their department.
2. Retrieve customers who have placed more than 5 orders.
3. List products that have never been ordered.
4. Identify the second highest salary in the company using a subquery.
5. Find departments where all employees earn above a specific threshold.

➤ 𝗔𝗴𝗴𝗿𝗲𝗴𝗮𝘁𝗲 𝗙𝘂𝗻𝗰𝘁𝗶𝗼𝗻𝘀

1. Calculate the total revenue generated by each product.


2. Find the average salary in each department.
3. Count the number of orders placed by each customer.
4. Find the maximum and minimum sales for each region.
5. Calculate the standard deviation of employee salaries.

➤ 𝗜𝗻𝗱𝗲𝘅𝗶𝗻𝗴 𝗮𝗻𝗱 𝗣𝗲𝗿𝗳𝗼𝗿𝗺𝗮𝗻𝗰𝗲

1. Identify queries that would benefit from indexing.


2. Compare execution plans with and without an index on a specific column.
3. Check which indexes exist on a table.
4. Optimize a slow query using indexing.
5. Write a query to update a column using an indexed lookup.

SQL Questions

1. Calculate the cancellation rate for each room type over the last 6 months, considering only
bookings with a minimum stay of 2 nights.
2. Determine the average conversion rate (confirmed bookings vs. search events) for users grouped
by their country and device type.
3. Identify properties that have consistently underperformed compared to the average booking rate
of their region over the last 12 months.
4. Detect instances of demand surge where the number of bookings in an hour exceeds the hourly
average by more than 50%.
5. What challenges might arise when querying sharded databases, especially for calculating global
metrics like average booking rates?
6. Explain how you would handle booking timestamps originating from different time zones when
querying for global daily booking patterns.
7. how would you balance normalization for data integrity and denormalization for query
performance?
8. If two systems simultaneously update the same booking record, what mechanisms would you use
in SQL to prevent data conflicts and ensure consistency?
9. Explain the scenarios where window functions outperform traditional group-by clauses in SQL.

Guesstimate Questions

1. Estimate the total number of hotel bookings made globally in a day on Booking.com
. Explain the factors and assumptions you would consider to arrive at your estimate.
2. How many unique users do you think search for flights on Booking.com
in a month? Provide a structured approach to your calculation.

Case Study Questions


1. You notice a sudden drop in conversion rates (from search to booking) for hotels in a particular
city. How would you investigate the root cause and propose solutions?
2. Booking.com
is launching a new feature that allows users to book multi-city trips. How would you measure the
success of this feature post-launch, and what metrics would you track to ensure its adoption and
profitability?

SQL Questions

1️⃣Write a query to find the cumulative revenue by month for each product category in a sales
table.
2️⃣How would you retrieve the top 5 products by sales volume, excluding any products that had
zero sales in the past 3 months?
3️⃣Given a table of customer transactions, identify all customers who made purchases in two or
more consecutive months.
4️⃣Write a query to calculate the retention rate of users on a monthly basis.
5️⃣Find the nth highest salary from an employee table, where n is passed dynamically to the
query.
6️⃣Explain how indexing works in SQL and how to decide which columns should be indexed for
optimal performance.
7️⃣Describe the differences between LEFT JOIN, RIGHT JOIN, and FULL OUTER JOIN, and when
to use each in a complex query.
8️⃣What is the difference between HAVING and WHERE clauses in SQL? When would you use
each?

PayPal Data Analyst Interview Experience :


CTC - 20 LPA

Question 1: Final Account Balance


Write a SQL query to retrieve the final account balance for each account by calculating the net
amount from deposits and withdrawals.

Input Table:
• transactions table:
- transaction_id (integer)
- account_id (integer)
- amount (decimal)
- transaction_type (varchar)

Question 2: Average Transaction Amount per User


Write a SQL query to compute the average transaction amount for each user and rank the users in
descending order based on their average transaction amount.

Input Table:
• transactions table:
- transaction_id (integer)
- user_id (integer)
- transaction_date (date)
- amount (decimal)

Question 3: Unique Money Transfer Relationships


Write a SQL query to determine the number of unique two-way money transfer relationships, where a
two-way relationship is established if a user has sent money to another user and also received
money from the same user.

Input Table:
• payments table:
- payer_id (integer)
- recipient_id (integer)
- amount (integer)

Question 4: Determining High-Value Customers


Write a SQL query to identify users who, in the last month, have either sent payments over 1000 or
received payments over 5000, excluding those flagged as fraudulent.

Input Tables:
• transactions table:
- transaction_id (integer)
- user_id (integer)
- transaction_date (date)
- transaction_type (varchar)
- amount (decimal)

• users table:
- user_id (integer)
- username (text)
- is_fraudulent (boolean)

Question 5: Analyzing User Transaction Data


Write a SQL query that calculates the total and average transaction amount for each user, including
only those users who have made at least two transactions.
Input Tables:
• Users table:
- user_id (integer)
- signup_date (date)

• Transactions table:
- transaction_id (integer)
- user_id (integer)
- transaction_date (date)
- transaction_amount (decimal)
SQL Questions:

1. How would you optimize a slow-running query with multiple joins?


2. What is a recursive CTE, and can you provide an example of when to use it?
3. Explain the difference between clustered and non-clustered indexes and when to use each.
4. Write a query to find the second highest salary in each department.
5. How would you detect and resolve deadlocks in SQL?
6. Explain window functions and provide examples of ROW_NUMBER, RANK, and DENSE_RANK.
7. Describe the ACID properties in database transactions and their significance.
8. Write a query to calculate a running total with partitions based on specific conditions.

Airbnb Business Analyst Interview Experience:


CTC - 25 LPA

SQL Questions:

1. Retrieve Housing Data from Specific Cities

You’re a data analyst at Airbnb and you’ve been tasked with retrieving housing data from specific
cities. You want to find all Airbnb listings in San Francisco and New York that have at least 10
reviews and an average rating equal to or above 4.5.

Tables:
• listings: listing_id (integer), name (string), city (string), reviews_count (integer)
• reviews: listing_id (integer), review_id (integer), stars (integer), submit_date (date)

2. Find the Average Number of Guests per Booking in Each City for Airbnb

As an analyst at Airbnb, one of the most useful insights you could provide would be to understand
the average number of guests per booking across locations. For this question, we would like you to
write a SQL query that will find the average number of guests per booking in each city.

Tables:
• bookings: booking_id (integer), property_id (integer), guests (integer), booking_date (date)
• properties: property_id (integer), city (string)

3. Analyzing Click-Through Rates for Airbnb Listing Views and Bookings

The scenario is that Airbnb wants to analyze the click-through conversion rates (CTRs) of their
listings. The CTR is calculated by dividing the number of bookings by the number of listing views,
giving a proportion of views that resulted in a booking.

Tables:
• listing_views: view_id (integer), user_id (integer), visit_date (date), listing_id (integer)
• bookings: booking_id (integer), user_id (integer), booking_date (date), listing_id (integer)

4. Average Vacant Days in 2021 for Active Listings

The strategy team in Airbnb is trying to analyze the impact of Covid-19 during 2021. To do so, they
need you to write a query that outputs the average vacant days across the AirBnbs in 2021. Some
properties have gone out of business, so you should only analyze rentals that are currently active.
Round the results to a whole number.

Assumptions:
• is_active field equals 1 when the property is active, and 0 otherwise.
• In cases where the check-in or check-out date is in another year other than 2021, limit the
calculation to the beginning or end of the year 2021 respectively.
• A listing can be active even if there are no bookings throughout the year.

Tables:
• bookings: listing_id (integer), checkin_date (date), checkout_date (date)
• listings: listing_id (integer), is_active (integer)

Most Asked SQL Interview Questions


1. Find the nth highest salary from an employee table.
2. Retrieve duplicate records from a table.
3. Delete duplicate rows while keeping only one copy.
4. Find employees with the highest salary in each department.
5. How do you generate a running total in SQL?
6. How do you find the second maximum value without using LIMIT or TOP?
7. How do you swap values of two columns in a table?
8. Write a SQL query to transpose rows into columns.
9. Write a SQL query to get the cumulative sum of a column.
10. How do you generate random rows from a table?

SQL Query Optimization Interview Questions


1. What is an index? How does it help?
2. What are the different types of indexes?
3. What is the difference between clustered and non-clustered indexes?
4. How does indexing impact INSERT and DELETE operations?
5. Explain partitioning in databases.
6. What is the difference between sharding and partitioning?
7. Why should you avoid using SELECT * in queries?
8. How do you optimize a query that runs slow?
9. What is a query execution plan, and how do you analyze it?
10. How do you find unused indexes in a database?

SQL System Design Interview Questions


You can expect these types of questions in the Advanced SQL Interview Questions
asked in FAANG

1. How would you design a database for an e-commerce system?


2. How do you efficiently store and query time-series data?
3. What are the best practices for handling large datasets in SQL?
4. How do you ensure data consistency across multiple database nodes?
5. What is database sharding, and how does it work?
6. How do you handle schema changes in a production database?
7. How would you design a real-time analytics system in SQL?
8. What are database migrations, and how do you manage them?
9. What is the best way to store and retrieve hierarchical data in SQL?
10. How do you monitor and improve SQL database performance over time?
11. What is the ACID property in a database?

Transactions and Concurrency Interview Questions


1. What are the different types of database locks?
2. Explain the concept of deadlocks in SQL.
3. What is the difference between pessimistic and optimistic locking?
4. How do you prevent deadlocks in SQL?
5. Explain the SERIALIZABLE and READ COMMITTED isolation levels.
6. What is the purpose of the SAVEPOINT command?
7. How do you roll back a transaction in SQL?
8. Explain dirty reads, phantom reads, and non-repeatable reads.
9. What is MVCC (Multi-Version Concurrency Control)?
10. How do you handle long-running transactions efficiently?

SQL Theory Interview Questions


1. What is the difference between a heap table and an indexed table?
2. Explain normalization and its different forms.
3. What is denormalization, and when should you use it?
4. What is a cross join, and when should it be used?
5. Explain star schema vs. snowflake schema.
6. What is OLAP vs. OLTP?
7. How do you design a high-availability database system?
8. What is the CAP theorem in distributed databases?
9. Explain the concept of eventual consistency in NoSQL databases.
10. What are the advantages of using NoSQL over SQL?

SQL Hard Interview Questions


You can expect these types of questions in the Advanced SQL Interview Questions
asked in FAANG

1. Write a query to find missing numbers in a sequence.


2. Given a table with start and end times, find the total overlapping time.
3. Reverse the order of words in a given column.
4. Write a query to remove HTML tags from a text column.
5. Find the longest consecutive sequence of numbers in a column.
6. Write a query to find the top 3 most common values in a column.
7. How do you perform fuzzy matching in SQL?
8. Generate a random password using SQL functions.
9. JOIN vs. EXISTS vs. IN
10. Write a query to find all employees reporting to a given manager.
11. Given a table of room bookings, find overlapping reservations.
12. Find cases where sales in one month dropped more than 50% compared to the previous
month.

Advanced SQL Aggregation Interview Questions


1. Find Top 3 Sales per Region Using NTILE()
2. Find Customers Who Made Purchases in Consecutive Months
3. How do you find months where revenue dropped by more than 30% compared to the
previous month?
4. How do you ensure missing dates appear in the report with zero sales?
5. Write a query to compute total sales per region, per product, and overall total in a single
query.
6. How do you calculate the percentage of total sales each region contributes?
7. How do you find the first and last transaction for each customer?
8. How do you compute a 3-month moving average of sales for each product?
9. How do you rank products based on total sales in descending order?
10. Write a query to calculate the cumulative sum of sales per customer, ordered by
transaction date.

Advanced Error Handling & Debugging interview


questions
1. How do you prevent a division by zero error when calculating a ratio in SQL?
2. How do you debug a stored procedure in SQL Server?
3. How do you handle deadlocks in SQL Server?
4. What happens when you aggregate a column that contains NULL values? How do you
handle it?
5. How do you debug PL/SQL stored procedures in Oracle?
6. How do you handle errors inside a MySQL stored procedure?
7. How do you log errors in PostgreSQL?
8. How do you handle errors when converting a string to an integer in SQL Server?
9. How do you ensure that a transaction is rolled back when an error occurs?
10. How do you capture query execution errors in Oracle?

Stored Procedure and CTE Interview Questions


1. What is a Stored Procedure, and why use it?
2. How do you create and execute a Stored Procedure in SQL Server?
3. How do you handle errors inside a Stored Procedure?
4. How do you implement a Stored Procedure with an output parameter?
5. How do you call a Stored Procedure inside another Stored Procedure?
6. What is the difference between Stored Procedures and Functions?
7. How do you optimize a Stored Procedure for performance?
8. What is a Common Table Expression (CTE), and why use it?
9. What is the difference between a CTE and a Temporary Table?
10. How do you write a Recursive CTE?
11. How do you use CTE for pagination?
12. Can a CTE be used inside a Stored Procedure?

Advanced Joins in SQL Interview Questions


1. What is a CROSS JOIN, and when do you use it?
2. How does a SELF JOIN work?
3. What is an ANTI JOIN, and how do you implement it?
4. What is a SEMI JOIN? How is it different from INNER JOIN?
5. How do you use a LATERAL JOIN?
6. How does INTERSECT work?
7. What is EXCEPT in SQL?
8. How do you find duplicate records using set operations?
9. What are the performance considerations for set operations?
10. How do you handle NULL values in set operations?

Complex Data Handling Interview Questions


1. How do you store and retrieve hierarchical data in SQL?
2. How do you handle multi-valued attributes in SQL?
3. How do you efficiently update large datasets?
4. What are the pros and cons of storing BLOBs in a database?
5. How do you store time-series data efficiently?
6. How do you store and retrieve encrypted data in SQL?
7. How do you efficiently delete old records from a large table?
8. How do you optimize storage for high-volume insertions?
9. How do you improve read performance for analytical queries?
10. How do you prevent fragmentation in indexes?
Data Modeling Interview Questions
1. What is data modeling, and why is it important?
2. What is an entity-relationship (ER) model?
3. What is cardinality in data modeling?
4. Can you explain a scenario where denormalization is useful?
5. What is a surrogate key, and when should you use it?
6. What are the differences between a fact table and a dimension table?
7. What is a snowflake schema vs. a star schema?
8. How would you model data for a NoSQL document database (e.g., MongoDB)?
9. When would you choose a relational database over NoSQL?
10. How do you handle slowly changing dimensions (SCD)?
11. How do you model real-time streaming data in a database?
12. How do you design a scalable recommendation system?
13. How do you handle multi-tenant databases?

SQL Most Asked Query Interview Questions


1. In an EmployeeDetails table, we have 3 columns:-
Emp_id, Emp_Name, and Mgr_id

The Manager id is nothing but the employee id of some employee. Example

1, A, 2
2, B, 3
3, C, 4

B is the manager of A and C is the manager of B.


2. Now in the above example, we have used Inner join as a part of the self join, the above will
query will work fine for all the employees who have a Manager, but the Managing Director,
CEO’s, etc. won’t necessarily have a Manager. What part of the query will you change to
make sure all the employees of the company is present in the output.
3. Execution of SQL Queries in the backend
4. Write a query to get all the student with name length 10, starting with K and ending with z.
5. Can you use HAVING command without any aggregate function in SQL?
6. You have data on people have applied for a lottery ticket. The data consists of their name
and ticket number. You have to choose winners by selecting the people present in the
alternate rows (the first winner starting from row number 3). Write a query to make things
easy to select the winners.
7. We have the following values
10000
10000
20000
30000

30000
30000
What would be the result of row number, rank, and dense rank ?
8. Find all the students who either are male or live in Mumbai ( have Mumbai as a part of their
address).
9. Suppose there are two columns in employee table i.e. emp id and email.Get all the unique
domains like gmail.com, yahoo.com, outlook.com, etc.
10. Can you join two table without any common column?
11. Give the output for the following

SELECT ‘NITIN’+1
SELECT ‘NITIN’+’1’
SELECT(SELECT ‘NITIN’)\
SELECT ‘1’+1
SELECT 1+’1’
12. Select case when null=null then ‘Amit’ else ‘Rahul’ end from dual;
What will be the output of the above query?
13. Explain character-manipulation functions? Explains its different types in SQL.
CONCAT
SUBSTR
LENGTH
INSTR
LPAD
RPAD
TRIM
REPLACE
14. Get the number of duplicate names and their frequency

Table – Employee
Name
Nitin
Amit
Gaurav
Nitin
Amit

Output

Nitin – 2
Amit – 2
Gaurav – 1

15. You always have a big data i.e. millions of rows in your tables, how would you partition it
for optimum performance?
16. Suppose in class, you have 3n boys and 2n girls with their names tabulated along with
their weight and gender. Write a SQL query to separate students alphabetically who are
over-weight (55kg for girls, 75kg for boys)
17. How can you create an empty table from an existing table? Write the steps and explain the
working.
18. What is the use of IFNULL and ISNULL in SQL?
19. You have got some data in the Table 1 and Table 2
Write a SQL query to create a Table 3 that contains the following columns- Id, First_Name,
Last_Name, Salary
20. What is CROSS JOIN UNNEST in Presto ?
21. What is LATERAL VIEW explode in Hive?
22. Suppose there are two tables, X and Y, X has just one column A and Y has B.
These are the two tables

Table X
Column A
1
1
1

Table Y
Column B
1
1
1
1
1

How many rows will be populated if you do


X left join Y
X inner join Y
X cross join Y
X right join Y

23. Pivot a table in SQL without using pivot function

Suppose there are two columns


Age Name
25 Nitin
30 Amit
27 Rishab

29 Ankush
Convert into
Name Nitin. Amit. Rishab. Ankush
Age. 25. 30. 27. 29

24. Get all employee detail from EmployeeDetail table whose


“FirstName” not start with any single character between ‘a-p’
25. Assume the name of table and columns
There are two tables with a common column. Which one will take more processing time
– Outer Join
– Full Outer Join
– Cartesian Join
26. Could you tell output or result of following SQL statements?
(Hint- In some cases, there may be an error. So, try to locate them and answer
accordingly)

select 5
select ‘5’
select count (‘5’)
select count (5)
select count (*)
27. Find the number of people who are from Delhi and have arrived in Patna in the last 7 days
28. Write a SQL query to find all the patients who joined in the year 2022.
29. State the differences between views and tables.
30. Given a table dbo.users where the column user_id is a unique numeric identifier, how can
you efficiently select the first 100 odd user_id values from the table?
31. What will be the output of the below query, given an Employee table having 10 records?

BEGIN TRAN
TRUNCATE TABLE Employees
ROLLBACK
SELECT * FROM Employees

32. There is a table which contains two columns Student and Marks, you need to find all the
students, whose marks are greater than average marks i.e. list of above-average students.
33. How to Show the Max marks and min marks together from student table?
34. What do we need to check in Database Testing?

Date and Time Interview Questions in SQL


1. Find the number of days between two dates.
2. Get the current date and time in SQL.
3. Find employees who joined in the last 6 months.
4. Extract the year, month, and day from a timestamp.
5. Convert a string into a DATE format in SQL
6. Find employees who have birthdays this month.
7. How do you get the last day of the month for a given date?
8. Write a query to generate all dates between two given dates.
9. How do you calculate the age of a person from a birth date?
10. Find the week number for a given date.

Basic SQL Questions Asked in Analytics Interviews


1. What is the difference between INNER JOIN, LEFT JOIN, RIGHT JOIN, and FULL JOIN?
2. What is the difference between HAVING and WHERE?
3. What is the purpose of the GROUP BY clause?
4. Explain the difference between COUNT(*) and COUNT(column_name).
5. What is the difference between CHAR and VARCHAR?
6. What is the difference between UNION and UNION ALL?
7. What are ACID properties in databases?
8. Explain the difference between DELETE, TRUNCATE, and DROP.
9. What is a primary key vs. a unique key?
10. What is the difference between DISTINCT and GROUP BY?
11. Can we use an aggregate function without the Group by keyword?

You might also like