QA
🐬
Database

SQL & MySQL Interview Questions

SQL queries, normalization rules, deadlock resolution, transaction isolation levels, partition strategies, and storage engines.

🎯 Ready to test your knowledge?

Take SQL & MySQL Skill Assessment Quiz

First prepare from the 100 learning questions below, then test your skills with 15 random MCQs categorized into Beginner, Intermediate, and Senior levels.

Launch 15-MCQ Quiz →
Experience Level:

Showing 100 Questions

Beginner LevelSQL & MySQL

1. How do B-Tree Indexes work in SQL/MySQL and how do you optimize slow queries using EXPLAIN?

❓ Context: Explain B-Tree index structure, composite index column ordering rule (Leftmost Prefix Rule), and EXPLAIN ANALYZE output.

A B-Tree index in MySQL InnoDB stores data in a balanced tree structure where lookups, insertions, and deletions take $O(\log N)$ time.

Leftmost Prefix Rule:

A composite index on '(A, B, C)' can satisfy queries filtering on '(A)', '(A, B)', or '(A, B, C)', but NOT '(B)' or '(C)' alone.

EXPLAIN ANALYZE:

Running EXPLAIN ANALYZE reveals execution plans, scan types (type: ref, range, or ALL full table scan), and total rows examined.

sql
-- Creating composite index following query access patterns
CREATE INDEX idx_users_status_created ON users(status, created_at);

-- Query using leftmost prefix (status = 'ACTIVE' and created_at range)
EXPLAIN ANALYZE
SELECT id, email, created_at
FROM users
WHERE status = 'ACTIVE'
  AND created_at >= '2026-01-01'
ORDER BY created_at DESC;
💡SQL composite indexing and EXPLAIN ANALYZE inspection.
🎯 Interview Key Takeaway

Always design composite indexes based on equality filter columns first, followed by range filters and sorting columns.

#SQL#MySQL#Indexes#Performance#EXPLAIN#Beginner
Permalink
Beginner LevelSQL & MySQL

2. How do SELECT, WHERE, ORDER BY, and LIMIT clauses filter relational datasets?

Beginner LevelSQL & MySQL

3. What are INNER JOIN, LEFT JOIN, RIGHT JOIN, and FULL OUTER JOIN?

Beginner LevelSQL & MySQL

4. How do GROUP BY and HAVING clauses work alongside aggregate functions (COUNT, SUM, AVG)?

Beginner LevelSQL & MySQL

5. What are Primary Keys, Foreign Keys, and Referential Integrity constraints?

Beginner LevelSQL & MySQL

6. How do INSERT, UPDATE, and DELETE DML operations modify relational tables?

Beginner LevelSQL & MySQL

7. What are standard SQL Data Types (VARCHAR vs CHAR, INT, DECIMAL, DATETIME)?

Beginner LevelSQL & MySQL

8. What are the ACID properties of relational database transactions?

Beginner LevelSQL & MySQL

9. What is Database Normalization (1NF, 2NF, 3NF, BCNF)?

Beginner LevelSQL & MySQL

10. What are Subqueries (Scalar, Correlated) and how does EXISTS work?

Beginner LevelSQL & MySQL

11. What is the difference between UNION and UNION ALL?

Beginner LevelSQL & MySQL

12. How does SELECT DISTINCT eliminate duplicate result rows?

Beginner LevelSQL & MySQL

13. How does SQL handle NULL values using IS NULL and COALESCE()?

Beginner LevelSQL & MySQL

14. How do ALTER TABLE statements modify database schemas dynamically?

Beginner LevelSQL & MySQL

15. What are SQL Views and when should you use CREATE VIEW?

Beginner LevelSQL & MySQL

16. How do LIKE wildcards (% and _) execute pattern matching in SQL?

Beginner LevelSQL & MySQL

17. How does CASE WHEN THEN ELSE END implement conditional logic in queries?

Beginner LevelSQL & MySQL

18. What is the difference between TRUNCATE and DELETE in SQL?

Beginner LevelSQL & MySQL

19. How do AUTO_INCREMENT and IDENTITY columns generate surrogate keys?

Beginner LevelSQL & MySQL

20. What is the difference between a UNIQUE Constraint and a UNIQUE Index?

Beginner LevelSQL & MySQL

21. What built-in String Functions exist (CONCAT, SUBSTRING, LENGTH, LOWER)?

Beginner LevelSQL & MySQL

22. How do Date Functions (NOW, DATE_ADD, DATEDIFF, EXTRACT) manipulate timestamps?

Beginner LevelSQL & MySQL

23. How do ON DELETE CASCADE and ON DELETE SET NULL handle foreign key deletions?

Beginner LevelSQL & MySQL

24. What is the difference between InnoDB and MyISAM storage engines in MySQL?

Beginner LevelSQL & MySQL

25. What is a CROSS JOIN and when does it produce a Cartesian Product?

Beginner LevelSQL & MySQL

26. What is a Self-Join and how is it used for organizational hierarchies?

Beginner LevelSQL & MySQL

27. How do BETWEEN and IN operators filter range and set conditions?

Beginner LevelSQL & MySQL

28. How do ANY, SOME, and ALL operators compare values against subquery lists?

Beginner LevelSQL & MySQL

29. What are Temporary Tables (CREATE TEMPORARY TABLE) and session scopes?

Beginner LevelSQL & MySQL

30. What is the syntax for single-line and multi-line comments in SQL?

Intermediate LevelSQL & MySQL

31. What are SQL Window Functions (ROW_NUMBER, RANK, DENSE_RANK, OVER)?

Intermediate LevelSQL & MySQL

32. What are Common Table Expressions (CTEs) and Recursive CTEs?

Intermediate LevelSQL & MySQL

33. What are Transaction Isolation Levels (READ UNCOMMITTED, READ COMMITTED, REPEATABLE READ, SERIALIZABLE)?

Intermediate LevelSQL & MySQL

34. What causes SQL Database Deadlocks and how do relational engines resolve them?

Intermediate LevelSQL & MySQL

35. Compare Clustered Indexes vs Non-Clustered Indexes vs Covering Indexes.

Intermediate LevelSQL & MySQL

36. What is the difference between Stored Procedures and User-Defined Functions (UDFs)?

Intermediate LevelSQL & MySQL

37. How do Database Triggers (BEFORE, AFTER, INSTEAD OF) execute automated logic?

Intermediate LevelSQL & MySQL

38. How do PIVOT and UNPIVOT operations transform rows into columns?

Intermediate LevelSQL & MySQL

39. How does UPSERT work using INSERT ... ON DUPLICATE KEY UPDATE in MySQL?

Intermediate LevelSQL & MySQL

40. What is Database Table Partitioning (Range, List, Hash) and Partition Pruning?

Intermediate LevelSQL & MySQL

41. How do LEAD() and LAG() window functions compare adjacent rows?

Intermediate LevelSQL & MySQL

42. How do FIRST_VALUE() and LAST_VALUE() extract boundary values in window frames?

Intermediate LevelSQL & MySQL

43. How does MySQL FULLTEXT Search work using MATCH() ... AGAINST() in Boolean Mode?

Intermediate LevelSQL & MySQL

44. How does the JSON Data Type and JSON_EXTRACT / -> operator work in MySQL 8+?

Intermediate LevelSQL & MySQL

45. How does a Cost-Based Optimizer (CBO) choose query execution plans?

Intermediate LevelSQL & MySQL

46. How do SAVEPOINT and ROLLBACK TO SAVEPOINT handle nested transaction rollbacks?

Intermediate LevelSQL & MySQL

47. How is Optimistic Locking implemented in SQL using a version or timestamp column?

Intermediate LevelSQL & MySQL

48. How does Pessimistic Locking work using SELECT ... FOR UPDATE?

Intermediate LevelSQL & MySQL

49. What is a Sargable Query (Search Argument Able) and why do functions break index usage?

Intermediate LevelSQL & MySQL

50. What is the InnoDB Buffer Pool and why is innodb_buffer_pool_size crucial?

Intermediate LevelSQL & MySQL

51. How does Database Connection Pooling reduce connection handshake overhead?

Intermediate LevelSQL & MySQL

52. What are Dirty Reads, Non-Repeatable Reads, and Phantom Reads?

Intermediate LevelSQL & MySQL

53. What are Generated (Computed) Columns in MySQL (VIRTUAL vs STORED)?

Intermediate LevelSQL & MySQL

54. How does the ANSI SQL MERGE statement perform atomic multi-row UPSERTs?

Intermediate LevelSQL & MySQL

55. Why was the Query Cache deprecated and removed in MySQL 8.0?

Intermediate LevelSQL & MySQL

56. What is MySQL Group Replication and how does Multi-Primary master replication operate?

Intermediate LevelSQL & MySQL

57. What are LATERAL Joins (CROSS APPLY) and how do they pass outer query values into subqueries?

Intermediate LevelSQL & MySQL

58. How do you configure and analyze the MySQL Slow Query Log?

Intermediate LevelSQL & MySQL

59. Why must Foreign Key columns be indexed in MySQL InnoDB?

Intermediate LevelSQL & MySQL

60. Why should you always use utf8mb4_unicode_ci collation in MySQL?

Intermediate LevelSQL & MySQL

61. Are CTEs materialized or inlined during query optimization?

Intermediate LevelSQL & MySQL

62. How do multi-row INSERT batch statements optimize bulk ingestion speed?

Intermediate LevelSQL & MySQL

63. What is Index Selectivity and how do you calculate Cardinality to optimize index ordering?

Intermediate LevelSQL & MySQL

64. What are Partial (Filtered) Indexes and how do they reduce index storage space?

Intermediate LevelSQL & MySQL

65. How do implicit collation mismatches cause full table scans during table joins?

Intermediate LevelSQL & MySQL

66. What is the Equality First, Range Second rule for Composite Index column ordering?

Intermediate LevelSQL & MySQL

67. How do FORCE INDEX and USE INDEX hints override MySQL query optimizer decisions?

Intermediate LevelSQL & MySQL

68. What is the difference between READ (Shared) Locks and WRITE (Exclusive) Locks?

Intermediate LevelSQL & MySQL

69. How do you inspect and reseed AUTO_INCREMENT / IDENTITY counters in SQL?

Intermediate LevelSQL & MySQL

70. What is the difference between Star Schema and Snowflake Schema in Data Warehousing?

Senior LevelSQL & MySQL

71. How does Multi-Version Concurrency Control (MVCC) work in MySQL InnoDB (Undo Logs and Read Views)?

Senior LevelSQL & MySQL

72. How do Next-Key Locks and Gap Locks in InnoDB eliminate Phantom Reads in REPEATABLE READ?

Senior LevelSQL & MySQL

73. How do Invisible Indexes enable safe, zero-downtime index removal in MySQL 8.0?

Senior LevelSQL & MySQL

74. How do Descending Indexes optimize multi-column sorting with mixed ASC/DESC order?

Senior LevelSQL & MySQL

75. How do Functional (Expression-Based) Indexes work in MySQL 8.0?

Senior LevelSQL & MySQL

76. How does the Redo Log (Write-Ahead Log) guarantee crash recovery in InnoDB?

Senior LevelSQL & MySQL

77. What is the role of the Undo Log and Purge Thread in InnoDB MVCC cleanup?

Senior LevelSQL & MySQL

78. What is the Doublewrite Buffer in InnoDB and how does it prevent partial page write corruption?

Senior LevelSQL & MySQL

79. What is the Adaptive Hash Index (AHI) in InnoDB and when should it be disabled?

Senior LevelSQL & MySQL

80. How do modern SQL Optimizers handle CTE Inlining versus Derived Table Materialization?

Senior LevelSQL & MySQL

81. What is a Loose Index Scan (Skip Scan) and how does it optimize GROUP BY and range queries?

Senior LevelSQL & MySQL

82. How does Index Condition Pushdown (ICP) optimize composite index filtering?

Senior LevelSQL & MySQL

83. How do Multi-Valued Indexes index JSON arrays in MySQL 8.0?

Senior LevelSQL & MySQL

84. How do gh-ost and pt-online-schema-change execute zero-downtime schema migrations on massive tables?

Senior LevelSQL & MySQL

85. How do GTID (Global Transaction Identifiers) and Semi-Synchronous Replication eliminate replication lag data loss?

Senior LevelSQL & MySQL

86. How does Transaction-Level Connection Pooling (PgBouncer) scale database client capacity?

Senior LevelSQL & MySQL

87. How do you select an optimal Shard Key to prevent hotspotting in distributed database sharding?

Senior LevelSQL & MySQL

88. How do Flashback / Time-Travel queries read historical data versions using System Versioned tables?

Senior LevelSQL & MySQL

89. How does InnoDB Buffer Pool LRU Scan Resistance prevent full table scans from flushing hot cache pages?

Senior LevelSQL & MySQL

90. How does Dynamic Partition Pruning optimize partitioned table join performance?

Senior LevelSQL & MySQL

91. What is Index Merge Optimization in MySQL and when should you replace it with a Composite Index?

Senior LevelSQL & MySQL

92. Compare Hash Aggregation versus Stream (Sort) Aggregation in SQL execution engines.

Senior LevelSQL & MySQL

93. What is Adaptive Query Execution (AQE) and how do modern engines adjust execution plans at runtime?

Senior LevelSQL & MySQL

94. What is the difference between a Database Lock and an Internal Database Latch?

Senior LevelSQL & MySQL

95. How do you prevent temporary tables from spilling to disk by tuning tmp_table_size and max_heap_table_size?

Senior LevelSQL & MySQL

96. Compare Row-Oriented (OLTP InnoDB) vs Columnar-Oriented (OLAP ClickHouse / DuckDB) database storage.

Senior LevelSQL & MySQL

97. How do you execute zero-downtime database migrations during blue-green application deployments?

Senior LevelSQL & MySQL

98. How do you diagnose and fix sudden Query Plan Regressions using Optimizer Hints and Plan Baselines?

Senior LevelSQL & MySQL

99. How do 2PC (Two-Phase Commit) and Saga Patterns coordinate transactions across sharded SQL databases?

Senior LevelSQL & MySQL

100. What is the future trajectory of Database Engineering (AI Query Optimization, Vector Databases, and Autonomous Databases)?

How to Prepare for SQL & MySQL Technical Interviews in 2026

When interviewing for software engineering positions that utilize SQL & MySQL, hiring managers look for a combination of fundamental syntax proficiency, architectural understanding, code optimization techniques, and practical debugging skills.

🌱 Beginner FocusCore syntax, default configurations, standard API definitions, and avoiding common basic errors.
⚡ Intermediate FocusAsync execution patterns, performance profiling, component lifecycle, and state management.
🏆 Senior FocusInternal runtime mechanics, memory leaks, scalability bottlenecks, system design trade-offs, and security mitigation.