Skip to content

SQL Interview Questions

This document provides a curated list of SQL interview questions commonly asked in technical interviews. It covers topics ranging from basic SQL syntax and data types to advanced concepts like joins, subqueries, window functions, and database design. The list is updated frequently to serve as a comprehensive reference for interview preparation.


Sno Question Title Practice Links Companies Asking Difficulty Topics
1 Difference between DELETE, TRUNCATE, and DROP GeeksforGeeks Most Tech Companies Easy DDL, DML
2 Types of SQL Joins (INNER, LEFT, RIGHT, FULL) W3Schools Google, Amazon, Meta Easy Joins
3 What is Normalization? Explain different forms. StudyTonight Microsoft, Oracle, IBM Medium Database Design, Normalization
4 Explain Primary Key vs Foreign Key vs Unique Key GeeksforGeeks Most Tech Companies Easy Constraints, Database Design
5 What are Indexes and why are they important? Essential SQL Google, Amazon, Netflix Medium Performance Optimization, Indexes
6 Write a query to find the Nth highest salary. LeetCode Amazon, Microsoft, Uber Medium Subqueries, Window Functions, Ranking
7 Explain ACID properties in Databases. GeeksforGeeks Oracle, SAP, Banks Medium Transactions, Database Fundamentals
8 What is a Subquery? Types of Subqueries. SQLTutorial.org Meta, Google, LinkedIn Medium Subqueries, Query Structure
9 Difference between UNION and UNION ALL. W3Schools Most Tech Companies Easy Set Operations
10 What are Window Functions? Give examples. Mode Analytics Netflix, Airbnb, Spotify Hard Window Functions, Advanced SQL
11 Explain Common Table Expressions (CTEs). SQLShack Microsoft, Google Medium CTEs, Query Readability
12 How to handle NULL values in SQL? SQL Authority Most Tech Companies Easy NULL Handling, Functions (COALESCE, ISNULL)
13 What is SQL Injection and how to prevent it? OWASP All Security-Conscious Medium Security, Best Practices
14 Difference between GROUP BY and PARTITION BY. Stack Overflow Advanced Roles Hard Aggregation, Window Functions
15 Write a query to find duplicate records in a table. GeeksforGeeks Data Quality Roles Medium Aggregation, GROUP BY, HAVING
16 Difference between WHERE and HAVING clause. SQLTutorial.org Most Tech Companies Easy Filtering, Aggregation
17 What are Triggers? Give an example. GeeksforGeeks Database Roles Medium Triggers, Automation
18 Explain different types of relationships (1:1, 1:N, N:M). Lucidchart Most Tech Companies Easy Database Design, Relationships
19 What is a View in SQL? W3Schools Google, Microsoft Easy Views, Abstraction
20 How to optimize a slow SQL query? [Several Resources] Performance Engineers Hard Performance Tuning, Optimization
21 Difference between ROW_NUMBER(), RANK(), DENSE_RANK(). SQLShack Data Analysts, Scientists Medium Window Functions, Ranking
22 What is Database Denormalization? When to use it? GeeksforGeeks Performance-critical Apps Medium Database Design, Performance
23 Explain Stored Procedures. Advantages? SQLTutorial.org Oracle, Microsoft Medium Stored Procedures, Reusability
24 How does BETWEEN operator work? W3Schools Most Tech Companies Easy Operators, Filtering
25 What is the CASE statement used for? W3Schools Most Tech Companies Easy Conditional Logic
26 Explain Self Join with an example. GeeksforGeeks Amazon, Meta Medium Joins
27 What is the purpose of DISTINCT keyword? W3Schools Most Tech Companies Easy Deduplication, Querying
28 How to find the second highest value? [Various Methods] Common Interview Q Medium Subqueries, Window Functions
29 What is Referential Integrity? Techopedia Database Roles Medium Constraints, Data Integrity
30 Explain EXISTS and NOT EXISTS operators. SQLTutorial.org Google, LinkedIn Medium Subqueries, Operators
31 What is a Schema in a database? Wikipedia Most Tech Companies Easy Database Concepts
32 Difference between CHAR and VARCHAR data types. GeeksforGeeks Most Tech Companies Easy Data Types, Storage
33 How to concatenate strings in SQL? Database.Guide Most Tech Companies Easy String Manipulation
34 What is Data Warehousing? IBM BI Roles, Data Engineers Medium Data Warehousing, BI
35 Explain ETL (Extract, Transform, Load) process. AWS Data Engineers Medium ETL, Data Integration
36 What are Aggregate Functions? List some. W3Schools Most Tech Companies Easy Aggregation
37 How to handle transactions (COMMIT, ROLLBACK)? SQLTutorial.org Database Developers Medium Transactions, ACID
38 What is Database Sharding? DigitalOcean Scalability Roles Hard Scalability, Database Architecture
39 Explain Database Replication. Wikipedia High Availability Roles Hard High Availability, Replication
40 What is the LIKE operator used for? W3Schools Most Tech Companies Easy Pattern Matching, Filtering
41 Difference between COUNT(*) and COUNT(column). Stack Overflow Most Tech Companies Easy Aggregation, NULL Handling
42 What is a Candidate Key? GeeksforGeeks Database Design Roles Medium Keys, Database Design
43 Explain Super Key. GeeksforGeeks Database Design Roles Medium Keys, Database Design
44 What is Composite Key? GeeksforGeeks Database Design Roles Medium Keys, Database Design
45 How to get the current date and time in SQL? [Varies by RDBMS] Most Tech Companies Easy Date/Time Functions
46 What is the purpose of ALTER TABLE statement? W3Schools Database Admins/Devs Easy DDL, Schema Modification
47 Explain CHECK constraint. W3Schools Database Design Roles Easy Constraints, Data Integrity
48 What is DEFAULT constraint? W3Schools Database Design Roles Easy Constraints, Default Values
49 How to create a temporary table? [Varies by RDBMS] Developers Medium Temporary Storage, Complex Queries
50 What is SQL Injection? (Revisited for emphasis) OWASP All Roles Medium Security
51 Explain Cross Join. When is it useful? W3Schools Specific Scenarios Medium Joins, Cartesian Product
52 What is the difference between Function and Stored Procedure? GeeksforGeeks Database Developers Medium Functions, Stored Procedures
53 How to find the length of a string? [Varies by RDBMS] Most Tech Companies Easy String Functions
54 What is the HAVING clause used for? W3Schools Most Tech Companies Easy Filtering Aggregates
55 Explain database locking mechanisms. Wikipedia Database Admins/Archs Hard Concurrency Control
56 What are Isolation Levels in transactions? GeeksforGeeks Database Developers Hard Transactions, Concurrency
57 How to perform conditional aggregation? SQL Authority Data Analysts Medium Aggregation, Conditional Logic
58 What is a Pivot Table in SQL? SQLShack Data Analysts, BI Roles Hard Data Transformation, Reporting
59 Explain the MERGE statement. Microsoft Docs SQL Server Devs Medium DML, Upsert Operations
60 How to handle errors in SQL (e.g., TRY...CATCH)? Microsoft Docs SQL Server Devs Medium Error Handling
61 What is Dynamic SQL? Pros and Cons? SQLShack Advanced SQL Devs Hard Dynamic Queries, Flexibility, Security
62 Explain Full-Text Search. Wikipedia Search Functionality Medium Indexing, Searching Text
63 How to work with JSON data in SQL? [Varies by RDBMS] Modern App Devs Medium JSON Support, Data Handling
64 What is Materialized View? Wikipedia Performance Optimization Hard Views, Performance
65 Difference between OLTP and OLAP. GeeksforGeeks DB Architects, BI Roles Medium Database Systems, Use Cases
66 How to calculate running totals? Mode Analytics Data Analysts Medium Window Functions, Aggregation
67 What is a Sequence in SQL? Oracle Docs Oracle/Postgres Devs Medium Sequence Generation
68 Explain Recursive CTEs. SQLTutorial.org Advanced SQL Devs Hard CTEs, Hierarchical Data
69 How to find the median value in SQL? Stack Overflow Data Analysts Hard Statistics, Window Functions
70 What is Query Execution Plan? Wikipedia Performance Tuning Medium Query Optimization, Performance
71 How to use COALESCE or ISNULL? W3Schools Most Tech Companies Easy NULL Handling
72 What is B-Tree Index? Wikipedia Database Internals Medium Indexes, Data Structures
73 Explain Hash Index. PostgreSQL Docs Database Internals Medium Indexes, Data Structures
74 Difference between Clustered and Non-Clustered Index. GeeksforGeeks Database Performance Medium Indexes, Performance
75 How to grant and revoke permissions? W3Schools Database Admins Easy Security, Access Control
76 What is SQL Profiler / Tracing? Microsoft Docs Performance Tuning Medium Monitoring, Debugging
77 Explain database constraints (NOT NULL, UNIQUE, etc.). W3Schools Most Tech Companies Easy Constraints, Data Integrity
78 How to update multiple rows with different values? Stack Overflow Developers Medium DML, Updates
79 What is database normalization (revisited)? StudyTonight All Roles Medium Database Design
80 Explain 1NF, 2NF, 3NF, BCNF. GeeksforGeeks Database Design Roles Medium Normalization Forms
81 How to delete duplicate rows? GeeksforGeeks Data Cleaning Roles Medium DML, Data Quality
82 What is the INTERSECT operator? W3Schools Set Operations Roles Medium Set Operations
83 What is the EXCEPT / MINUS operator? W3Schools Set Operations Roles Medium Set Operations
84 How to handle large objects (BLOB, CLOB)? Oracle Docs Specific Applications Medium Data Types, Large Data
85 What is database connection pooling? Wikipedia Application Developers Medium Performance, Resource Management
86 Explain CAP Theorem. Wikipedia Distributed Systems Hard Distributed Databases, Tradeoffs
87 How to perform date/time arithmetic? [Varies by RDBMS] Most Tech Companies Easy Date/Time Functions
88 What is a correlated subquery? GeeksforGeeks Advanced SQL Users Medium Subqueries, Performance Considerations
89 How to use GROUPING SETS, CUBE, ROLLUP? SQLShack BI / Analytics Roles Hard Advanced Aggregation
90 What is Parameter Sniffing (SQL Server)? Brent Ozar SQL Server DBAs/Devs Hard Performance Tuning (SQL Server)
91 How to create and use User-Defined Functions (UDFs)? [Varies by RDBMS] Database Developers Medium Functions, Reusability
92 What is database auditing? Wikipedia Security/Compliance Roles Medium Security, Monitoring
93 Explain optimistic vs. pessimistic locking. Stack Overflow Concurrent Applications Hard Concurrency Control
94 How to handle deadlocks? Microsoft Docs Database Admins/Devs Hard Concurrency, Error Handling
95 What is NoSQL? How does it differ from SQL? MongoDB Modern Data Roles Medium Database Paradigms
96 Explain eventual consistency. Wikipedia Distributed Systems Hard Distributed Databases, Consistency Models
97 How to design a schema for a specific scenario (e.g., social media)? [Design Principles] System Design Interviews Hard Database Design, Modeling
98 What are spatial data types and functions? PostGIS GIS Applications Hard Spatial Data, GIS
99 How to perform fuzzy string matching in SQL? Stack Overflow Data Matching Roles Hard String Matching, Extensions
100 What is Change Data Capture (CDC)? Wikipedia Data Integration/Sync Hard Data Replication, Event Streaming
101 Explain Graph Databases and their use cases. Neo4j Specialized Roles Hard Graph Databases, Data Modeling

Questions asked in Google interviews

  1. Explain window functions and their applications in analytical queries.
  2. Write a query to find users who have logged in on consecutive days.
  3. How would you optimize a slow-performing query that involves multiple joins?
  4. Explain the difference between RANK(), DENSE_RANK(), and ROW_NUMBER().
  5. Write a query to calculate a running total or moving average.
  6. How would you handle hierarchical data in SQL?
  7. Explain Common Table Expressions (CTEs) and their benefits.
  8. What are the performance implications of using subqueries vs. joins?
  9. How would you design a database schema for a specific application?
  10. Explain how indexes work and when they should be used.

Questions asked in Amazon interviews

  1. Write a query to find the nth highest salary in a table.
  2. How would you identify and remove duplicate records?
  3. Explain the difference between UNION and UNION ALL.
  4. Write a query to pivot data from rows to columns.
  5. How would you handle time-series data in SQL?
  6. Explain the concept of database sharding.
  7. Write a query to find users who purchased products in consecutive months.
  8. How would you implement a recommendation system using SQL?
  9. Explain how you would optimize a query for large datasets.
  10. Write a query to calculate year-over-year growth.

Questions asked in Microsoft interviews

  1. Explain database normalization and denormalization.
  2. How would you implement error handling in SQL?
  3. Write a query to find departments with above-average salaries.
  4. Explain the different types of joins and their use cases.
  5. How would you handle slowly changing dimensions?
  6. Write a query to implement a pagination system.
  7. Explain transaction isolation levels.
  8. How would you design a database for high availability?
  9. Write a query to find the most frequent values in a column.
  10. Explain the differences between clustered and non-clustered indexes.

Questions asked in Meta interviews

  1. Write a query to analyze user engagement metrics.
  2. How would you implement a friend recommendation algorithm?
  3. Explain how you would handle large-scale data processing.
  4. Write a query to identify trending content.
  5. How would you design a database schema for a social media platform?
  6. Explain the concept of data partitioning.
  7. Write a query to calculate the conversion rate between different user actions.
  8. How would you implement A/B testing analysis using SQL?
  9. Explain how you would handle real-time analytics.
  10. Write a query to identify anomalies in user behavior.

Questions asked in Netflix interviews

  1. Write a query to analyze streaming patterns and user retention.
  2. How would you implement a content recommendation system?
  3. Explain how you would handle data for personalized user experiences.
  4. Write a query to identify viewing trends across different demographics.
  5. How would you design a database for content metadata?
  6. Explain how you would optimize queries for real-time recommendations.
  7. Write a query to calculate user engagement metrics.
  8. How would you implement A/B testing for UI changes?
  9. Explain how you would handle data for regional content preferences.
  10. Write a query to identify factors affecting user churn.

Questions asked in Apple interviews

  1. Explain database security best practices.
  2. How would you design a database for an e-commerce platform?
  3. Write a query to analyze product performance.
  4. Explain how you would handle data migration.
  5. How would you implement data validation in SQL?
  6. Write a query to track user interactions with products.
  7. Explain how you would optimize database performance.
  8. How would you implement data archiving strategies?
  9. Write a query to analyze customer feedback data.
  10. Explain how you would handle internationalization in databases.

Questions asked in LinkedIn interviews

  1. Write a query to implement a connection recommendation system.
  2. How would you design a database schema for professional profiles?
  3. Explain how you would handle data for skill endorsements.
  4. Write a query to analyze user networking patterns.
  5. How would you implement job recommendation algorithms?
  6. Explain how you would handle data for company pages.
  7. Write a query to identify trending job skills.
  8. How would you implement search functionality for profiles?
  9. Explain how you would handle data privacy requirements.
  10. Write a query to analyze user engagement with content.