Interview

Complete MySQL Interview Questions and Answers for Experienced Developers

This complete MySQL interview guide covers important questions from beginner to advanced level with detailed explanations, practical SQL examples and real-world scenarios. It is especially useful for PHP, Laravel and backend developers preparing for technical interviews.

  • MySQL interview questions
  • MySQL interview questions for experienced developers
  • SQL interview questions
  • MySQL interview questions for PHP developers
  • MySQL interview questions for Laravel developers
  • database interview questions
  • advanced MySQL int

Complete MySQL Interview Questions and Answers for Beginners to Experienced Developers

MySQL is one of the most commonly used relational database management systems in web development.

For PHP and Laravel developers, MySQL interview questions are especially important because database design, SQL optimization and data handling are core parts of backend development.

For experienced developers, interviewers usually go beyond simple SELECT, INSERT and UPDATE queries.

You may be asked about:

  • Joins
  • Subqueries
  • Indexes
  • Normalization
  • Transactions
  • ACID properties
  • Deadlocks
  • Query optimization
  • EXPLAIN
  • Stored procedures
  • Triggers
  • Views
  • Constraints
  • Concurrency
  • Large datasets
  • Real project database problems

This article covers MySQL interview questions from beginner to advanced level with practical examples.


MySQL Basic Interview Questions

1. What is MySQL?

MySQL is a relational database management system, commonly called an RDBMS.

It stores data in tables consisting of rows and columns.

MySQL uses SQL, or Structured Query Language, to create, retrieve, update and delete data.

For example:

SELECT * FROM users;

This retrieves all records from the users table.


2. What is a database?

A database is an organized collection of data.

For example, an e-commerce application's database may contain:

users
products
orders
order_items
payments
categories

Each table stores a specific type of information.


3. What is SQL?

SQL stands for Structured Query Language.

It is used to communicate with relational databases.

Common SQL operations include:

  • CREATE
  • SELECT
  • INSERT
  • UPDATE
  • DELETE
  • ALTER
  • DROP

4. What is the difference between SQL and MySQL?

SQL is a language used to work with relational databases.

MySQL is a database management system that supports SQL.

In simple terms:

SQL = Language

MySQL = Database software

5. What is a table?

A table stores data in rows and columns.

For example:

users

id | name   | email
-------------------------
1  | Bikram | b@example.com
2  | Rahul  | r@example.com

Each row represents one record.

Each column represents one attribute.


6. How do you create a database?

CREATE DATABASE ecommerce;

To select the database:

USE ecommerce;

7. How do you create a table?

CREATE TABLE users (
    id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    name VARCHAR(100) NOT NULL,
    email VARCHAR(150) NOT NULL UNIQUE,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

8. What is a primary key?

A primary key uniquely identifies each row in a table.

Example:

id BIGINT PRIMARY KEY

A primary key should be unique and cannot contain NULL values.


9. What is a foreign key?

A foreign key creates a relationship between two tables.

Example:

CREATE TABLE orders (
    id BIGINT PRIMARY KEY AUTO_INCREMENT,
    user_id BIGINT NOT NULL,

    FOREIGN KEY (user_id)
        REFERENCES users(id)
);

Here, user_id connects the orders table with users.


10. Primary key vs foreign key?

A primary key uniquely identifies a row within its own table.

A foreign key references a key in another table and establishes a relationship between tables.


SQL CRUD Interview Questions

11. How do you insert data?

INSERT INTO users (name, email)
VALUES ('Bikram', 'bikram@example.com');

12. How do you retrieve data?

SELECT * FROM users;

To retrieve specific columns:

SELECT id, name, email
FROM users;

Selecting only required columns is often better than unnecessarily using SELECT *.


13. How do you update data?

UPDATE users
SET name = 'Bikram Lenka'
WHERE id = 1;

Always be careful with the WHERE condition.

Without it:

UPDATE users
SET status = 0;

every row may be updated.


14. How do you delete a record?

DELETE FROM users
WHERE id = 10;

15. DELETE vs TRUNCATE vs DROP?

DELETE removes selected rows and can use a WHERE condition.

DELETE FROM users
WHERE id = 10;

TRUNCATE removes all rows from a table quickly.

TRUNCATE TABLE users;

DROP removes the entire table structure and its data.

DROP TABLE users;

WHERE and Filtering Questions

16. What is WHERE?

The WHERE clause filters records.

SELECT *
FROM users
WHERE status = 1;

17. How do AND and OR work?

SELECT *
FROM users
WHERE status = 1
AND city = 'Bhubaneswar';

With OR:

SELECT *
FROM users
WHERE city = 'Bhubaneswar'
OR city = 'Cuttack';

18. What is IN?

IN checks whether a value matches any value in a list.

SELECT *
FROM users
WHERE city IN ('Bhubaneswar', 'Cuttack', 'Puri');

19. What is BETWEEN?

BETWEEN checks whether a value falls within a range.

SELECT *
FROM products
WHERE price BETWEEN 500 AND 1000;

20. What is LIKE?

LIKE is used for pattern matching.

SELECT *
FROM users
WHERE name LIKE 'Bik%';

This finds names starting with Bik.

WHERE name LIKE '%ram%'

finds values containing ram.

Leading wildcards can make index usage less efficient for traditional B-tree indexes.


21. What is the difference between = and LIKE?

= is used for exact comparison.

WHERE name = 'Bikram'

LIKE supports pattern matching.

WHERE name LIKE 'Bik%'

22. What is IS NULL?

NULL represents the absence of a value.

Use:

SELECT *
FROM users
WHERE phone IS NULL;

Not:

WHERE phone = NULL

Sorting and Limiting Questions

23. What is ORDER BY?

ORDER BY sorts results.

SELECT *
FROM users
ORDER BY name ASC;

Descending:

ORDER BY created_at DESC;

24. What is LIMIT?

LIMIT restricts the number of records returned.

SELECT *
FROM users
LIMIT 10;

25. How does pagination work with LIMIT and OFFSET?

SELECT *
FROM users
ORDER BY id
LIMIT 20 OFFSET 40;

This skips 40 rows and returns the next 20.

For very large page numbers, large OFFSET values may become expensive.

Cursor/keyset pagination can often perform better.


Aggregate Function Questions

26. What are aggregate functions?

Aggregate functions calculate values across multiple rows.

Common functions include:

  • COUNT()
  • SUM()
  • AVG()
  • MIN()
  • MAX()

27. How do you count records?

SELECT COUNT(*)
FROM users;

Count active users:

SELECT COUNT(*)
FROM users
WHERE status = 1;

28. How do you calculate total sales?

SELECT SUM(total_amount)
FROM orders
WHERE status = 'completed';

29. What is AVG()?

SELECT AVG(price)
FROM products;

This returns the average product price.


GROUP BY and HAVING

30. What is GROUP BY?

GROUP BY groups rows with the same values so aggregate calculations can be performed for each group.

SELECT status, COUNT(*) AS total
FROM orders
GROUP BY status;

Possible output:

pending    10
completed  50
cancelled   5

31. WHERE vs HAVING?

WHERE filters rows before grouping.

HAVING filters groups after aggregation.

Example:

SELECT user_id, COUNT(*) AS total_orders
FROM orders
WHERE status = 'completed'
GROUP BY user_id
HAVING COUNT(*) > 5;

The WHERE condition filters individual orders.

The HAVING condition filters the grouped results.


JOIN Interview Questions

32. What is a JOIN?

A JOIN combines rows from multiple related tables.

Suppose we have:

users
orders

An order contains user_id.

We can combine them:

SELECT users.name, orders.total_amount
FROM users
JOIN orders
ON users.id = orders.user_id;

33. What is INNER JOIN?

INNER JOIN returns only matching rows from both tables.

SELECT u.name, o.total_amount
FROM users u
INNER JOIN orders o
ON u.id = o.user_id;

Users without orders are not returned.


34. What is LEFT JOIN?

LEFT JOIN returns all rows from the left table plus matching rows from the right table.

SELECT u.name, o.id AS order_id
FROM users u
LEFT JOIN orders o
ON u.id = o.user_id;

Users without orders are also returned.


35. INNER JOIN vs LEFT JOIN?

INNER JOIN returns only matching records.

LEFT JOIN keeps every row from the left table, even when there is no matching row in the right table.


36. How do you find customers who have never placed an order?

SELECT u.*
FROM users u
LEFT JOIN orders o
ON u.id = o.user_id
WHERE o.id IS NULL;

This is a very common SQL interview question.


37. What is a SELF JOIN?

A self join joins a table with itself.

Example: employees and their managers stored in the same table.

SELECT
    e.name AS employee,
    m.name AS manager
FROM employees e
LEFT JOIN employees m
ON e.manager_id = m.id;

Subquery Interview Questions

38. What is a subquery?

A subquery is a query placed inside another query.

SELECT *
FROM employees
WHERE salary > (
    SELECT AVG(salary)
    FROM employees
);

This returns employees whose salary is above the company average.


39. How do you find the second highest salary?

One approach:

SELECT MAX(salary)
FROM employees
WHERE salary < (
    SELECT MAX(salary)
    FROM employees
);

This returns the second distinct highest salary.


40. How do you find the Nth highest salary?

One option is to use ranking functions in MySQL versions that support window functions.

SELECT salary
FROM (
    SELECT
        salary,
        DENSE_RANK() OVER (
            ORDER BY salary DESC
        ) AS salary_rank
    FROM employees
) ranked
WHERE salary_rank = 3;

This retrieves the third distinct highest salary.


UNION Questions

41. What is UNION?

UNION combines result sets from multiple queries and removes duplicate rows.

SELECT email FROM customers

UNION

SELECT email FROM suppliers;

42. UNION vs UNION ALL?

UNION removes duplicates.

UNION ALL keeps duplicates.

Because UNION ALL does not need duplicate elimination, it can be faster when duplicate removal is unnecessary.


Constraints Interview Questions

43. What are database constraints?

Constraints enforce rules on data.

Common constraints include:

  • PRIMARY KEY
  • FOREIGN KEY
  • UNIQUE
  • NOT NULL
  • CHECK
  • DEFAULT

44. What is a UNIQUE constraint?

UNIQUE prevents duplicate values.

email VARCHAR(150) UNIQUE

This is very useful for fields such as email, username or external transaction reference when uniqueness is required.


45. Application validation vs database constraint?

Application validation improves the user experience.

Database constraints protect data integrity.

For important rules, both may be useful.

For example, checking whether an email exists in Laravel is useful, but the database should still enforce a UNIQUE constraint to protect against race conditions.


Normalization Interview Questions

46. What is normalization?

Normalization is the process of structuring database tables to reduce unnecessary duplication and improve data consistency.

For example, instead of storing customer details repeatedly inside every order:

orders

id
customer_name
customer_email
customer_phone

we can create:

customers

id
name
email
phone

and:

orders

id
customer_id
total

47. What is First Normal Form or 1NF?

1NF generally requires that each column contain atomic values and that repeating groups be avoided.

Bad:

phone_numbers =
'9876543210,9999999999'

A better design may store multiple phone records separately if multiple phone numbers must be modeled relationally.


48. What is Second Normal Form or 2NF?

2NF requires a table to be in 1NF and removes partial dependency on part of a composite key.

This is especially relevant when a table uses a composite primary key.


49. What is Third Normal Form or 3NF?

3NF requires the table to be in 2NF and aims to remove transitive dependencies.

In simpler terms, non-key columns should depend on the key rather than on another non-key column.


50. What is denormalization?

Denormalization intentionally introduces some duplicated or precomputed data to improve read performance.

It can be useful in reporting and analytics systems, but it creates synchronization complexity.

Normalization is not a rule that every application must maximize. Database design should reflect workload and data integrity requirements.


Index Interview Questions

51. What is an index?

An index is a data structure that helps MySQL locate records efficiently without scanning every row.

Example:

CREATE INDEX idx_users_email
ON users(email);

A query like:

SELECT *
FROM users
WHERE email = 'test@example.com';

may benefit from the index.


52. Why not create indexes on every column?

Indexes improve many read operations but also have costs.

Indexes require:

  • Additional storage
  • Maintenance during INSERT
  • Maintenance during UPDATE
  • Maintenance during DELETE

Indexes should be based on real query patterns.


53. Which columns are commonly good candidates for indexes?

Columns frequently used in:

  • WHERE
  • JOIN
  • ORDER BY
  • GROUP BY
  • Unique lookups

may benefit from indexes.


54. What is a composite index?

A composite index contains multiple columns.

CREATE INDEX idx_orders_user_status
ON orders(user_id, status);

This can help queries such as:

SELECT *
FROM orders
WHERE user_id = 10
AND status = 'completed';

55. Does column order matter in a composite index?

Yes.

For an index:

(user_id, status, created_at)

the order of columns affects which query patterns can efficiently use the index.

This is commonly explained through the leftmost-prefix principle.


56. What is a covering index?

A covering index contains the columns needed by a query so MySQL may be able to answer the query from the index without reading the full table row.

Whether this is beneficial depends on the query and index design.


EXPLAIN and Query Optimization

57. What is EXPLAIN?

EXPLAIN shows how MySQL plans to execute a query.

EXPLAIN
SELECT *
FROM orders
WHERE user_id = 100;

It can help identify:

  • Which indexes are considered
  • Which index is used
  • Approximate rows examined
  • Join strategy
  • Table scanning

58. Your query is slow. What would you check?

I would check:

  • Execution plan using EXPLAIN
  • Missing indexes
  • Number of rows scanned
  • Unnecessary SELECT *
  • JOIN conditions
  • ORDER BY and GROUP BY
  • Subqueries
  • Functions on indexed columns
  • Large OFFSET values
  • Database server load

59. Why can SELECT * be inefficient?

If a table contains 30 columns but the application only needs three, retrieving all columns wastes:

  • Database I/O
  • Network bandwidth
  • Application memory

Instead of:

SELECT *
FROM users;

use:

SELECT id, name, email
FROM users;

60. Why can functions on indexed columns affect performance?

Consider:

SELECT *
FROM orders
WHERE DATE(created_at) = '2026-09-30';

Applying a function to an indexed column may prevent efficient index usage in some query plans.

A range query can often be preferable:

SELECT *
FROM orders
WHERE created_at >= '2026-09-30 00:00:00'
AND created_at < '2026-10-01 00:00:00';

Transaction Interview Questions

61. What is a transaction?

A transaction groups multiple SQL operations into one logical unit of work.

Example:

START TRANSACTION;

UPDATE accounts
SET balance = balance - 1000
WHERE id = 1;

UPDATE accounts
SET balance = balance + 1000
WHERE id = 2;

COMMIT;

If something fails:

ROLLBACK;

62. What are ACID properties?

ACID stands for:

  • Atomicity
  • Consistency
  • Isolation
  • Durability

Atomicity

All operations in a transaction succeed or all fail.

Consistency

The database should remain in a valid state according to its constraints and rules.

Isolation

Concurrent transactions should be isolated according to the configured isolation level.

Durability

Once a transaction is committed, its changes should persist even after system failure, subject to the database engine's durability guarantees.


63. Give a real-world transaction example.

An order creation may involve:

Create order
↓
Create order items
↓
Reduce stock
↓
Create payment record

If one critical operation fails, the other changes may need to be rolled back.


Concurrency and Locking Questions

64. What is a race condition?

A race condition occurs when multiple operations access and modify shared data concurrently and the result depends on timing.

Example:

Stock = 1

Customer A reads stock = 1
Customer B reads stock = 1

Both place order

Now the application may oversell the product.


65. What is row-level locking?

Row-level locking allows a transaction to lock specific rows during a critical operation.

Example:

START TRANSACTION;

SELECT *
FROM products
WHERE id = 10
FOR UPDATE;

The application can then safely check and update stock before committing.


66. What is a deadlock?

A deadlock occurs when two transactions wait for locks held by each other.

Example:

Transaction A locks Row 1
Transaction B locks Row 2

Transaction A waits for Row 2
Transaction B waits for Row 1

Neither can continue.

MySQL can detect deadlocks and roll back one transaction.


67. How can deadlocks be reduced?

Strategies include:

  • Keep transactions short
  • Access rows in a consistent order
  • Use appropriate indexes
  • Avoid unnecessary locks
  • Retry transactions when appropriate

Isolation Level Questions

68. What are transaction isolation levels?

Common SQL transaction isolation levels are:

  • READ UNCOMMITTED
  • READ COMMITTED
  • REPEATABLE READ
  • SERIALIZABLE

Higher isolation can reduce some concurrency anomalies but may also reduce concurrency.


69. What is a dirty read?

A dirty read occurs when one transaction reads data written by another transaction that has not yet committed.

If the second transaction rolls back, the first transaction has read data that never became permanent.


70. What is a non-repeatable read?

A non-repeatable read occurs when the same row is read twice in one transaction and returns different committed values because another transaction updated it between the reads.


71. What is a phantom read?

A phantom read occurs when the same range query is executed multiple times and new matching rows appear because another transaction inserted them.


Views Interview Questions

72. What is a View?

A View is a stored query that behaves like a virtual table.

CREATE VIEW active_users AS
SELECT id, name, email
FROM users
WHERE status = 1;

Then:

SELECT *
FROM active_users;

73. Why use Views?

Views can help:

  • Simplify complex queries
  • Provide reusable query logic
  • Restrict exposed columns
  • Create reporting abstractions

Stored Procedure Questions

74. What is a stored procedure?

A stored procedure is a set of SQL statements stored in the database and executed as a unit.

Conceptually:

CALL GenerateMonthlyReport();

Stored procedures may be useful for database-centric operations, but many modern applications keep business logic in the application layer for maintainability and portability.


75. Stored procedure vs function?

A stored function returns a value and can often be used within SQL expressions.

A stored procedure can perform broader sets of database operations and can return results through different mechanisms.


Trigger Interview Questions

76. What is a trigger?

A trigger automatically executes when certain database events occur.

Typical events include:

  • INSERT
  • UPDATE
  • DELETE

Example use case:

Automatically create an audit record whenever sensitive data changes.


77. What are the disadvantages of triggers?

Triggers can make business behavior harder to discover because logic runs automatically inside the database.

Potential problems include:

  • Hidden side effects
  • Difficult debugging
  • Complex deployment
  • Database portability issues

They should be used when they provide a clear architectural benefit.


Data Type Questions

78. CHAR vs VARCHAR?

CHAR stores fixed-length strings.

VARCHAR stores variable-length strings.

VARCHAR is commonly used for names, emails and addresses.


79. INT vs BIGINT?

BIGINT supports a much larger integer range than INT but requires more storage.

The appropriate type depends on expected data size.


80. Why should DECIMAL be used for money instead of FLOAT?

FLOAT uses approximate floating-point representation.

Financial applications generally require precise decimal arithmetic.

Example:

amount DECIMAL(12,2)

This is usually more appropriate for currency values.


Date and Time Questions

81. DATETIME vs TIMESTAMP?

Both store date and time values, but they differ in storage behavior, supported ranges and timezone-related semantics.

The choice should be based on application requirements rather than assuming one is universally better.


82. How do you get today's records?

A range query:

SELECT *
FROM orders
WHERE created_at >= '2026-09-30 00:00:00'
AND created_at < '2026-10-01 00:00:00';

This can be preferable to applying DATE() to an indexed timestamp column.


Real-World MySQL Scenario Questions

83. Your table contains 5 lakh records and search becomes slow. What would you do?

I would first identify the slow query.

Then I would check:

  • Indexes
  • EXPLAIN output
  • Number of rows examined
  • Selected columns
  • WHERE conditions
  • JOIN conditions
  • Pagination
  • Sorting
  • Search patterns

I would not assume that having 500,000 rows itself is the problem.

A properly indexed database can efficiently handle datasets much larger than that depending on workload and infrastructure.


84. An admin page loads all 500,000 records. What would you change?

I would never load every record for a normal table listing.

I would use server-side pagination.

SELECT id, name, email
FROM users
ORDER BY id DESC
LIMIT 50;

I would also apply filters and indexes.


85. OFFSET pagination becomes slow on page 10,000. What can you do?

Large OFFSET values can require MySQL to scan and skip many rows.

Instead of:

SELECT *
FROM users
ORDER BY id
LIMIT 50 OFFSET 500000;

keyset pagination can use the last seen ID:

SELECT *
FROM users
WHERE id > 500000
ORDER BY id
LIMIT 50;

This can be significantly more efficient when the use case allows cursor-style navigation.


86. How would you find duplicate emails?

SELECT email, COUNT(*) AS total
FROM users
GROUP BY email
HAVING COUNT(*) > 1;

87. How would you remove duplicate records?

First identify why duplicates exist and decide which record should remain.

Do not immediately execute DELETE statements on production data.

After cleaning existing duplicates, add an appropriate unique constraint to prevent the issue from happening again.

ALTER TABLE users
ADD UNIQUE KEY unique_email (email);

88. How would you find the latest order for each customer?

Window functions can make this easier:

SELECT *
FROM (
    SELECT
        orders.*,
        ROW_NUMBER() OVER (
            PARTITION BY user_id
            ORDER BY created_at DESC
        ) AS row_num
    FROM orders
) ranked
WHERE row_num = 1;

89. What are window functions?

Window functions calculate values across related rows without collapsing them into a single row like GROUP BY does.

Examples include:

  • ROW_NUMBER()
  • RANK()
  • DENSE_RANK()
  • LAG()
  • LEAD()

90. ROW_NUMBER vs RANK vs DENSE_RANK?

Suppose salaries are:

100
100
90

ROW_NUMBER:

1
2
3

RANK:

1
1
3

DENSE_RANK:

1
1
2

91. You need to transfer ₹1,000 between two accounts. How would you protect consistency?

I would use a transaction.

START TRANSACTION;

UPDATE accounts
SET balance = balance - 1000
WHERE id = 1;

UPDATE accounts
SET balance = balance + 1000
WHERE id = 2;

COMMIT;

I would also validate sufficient balance and consider row locking for concurrent transfers.


92. Two users purchase the last product simultaneously. How would the database help?

I could use a transaction and lock the product row:

START TRANSACTION;

SELECT stock
FROM products
WHERE id = 100
FOR UPDATE;

Then validate stock and update it before committing.

This prevents competing transactions from incorrectly consuming the same inventory.


93. How do you prevent duplicate payment transactions?

Store the payment gateway transaction ID and add a UNIQUE constraint.

ALTER TABLE payments
ADD UNIQUE KEY unique_gateway_transaction (
    gateway_transaction_id
);

Even if the application accidentally processes the same callback twice, the database prevents duplicate transaction IDs.


94. A query uses WHERE email = ? thousands of times per minute. What would you check?

I would verify whether email has an appropriate index.

SHOW INDEX FROM users;

If necessary:

CREATE INDEX idx_users_email
ON users(email);

If email must be unique, a UNIQUE index may be more appropriate.


95. Why can too many indexes slow an application?

Every time a row is inserted, updated or deleted, relevant indexes may also need to be updated.

Therefore, over-indexing can increase:

  • Write time
  • Storage requirements
  • Maintenance cost

96. What is database cardinality?

Cardinality generally refers to the number of distinct values in a column or index.

A column with highly varied values such as email often has high cardinality.

A boolean column with only 0 and 1 has low cardinality.

Cardinality can influence index usefulness and query planning.


97. Why may an index on status not always help?

Suppose a table contains one million records and 950,000 have:

status = 1

A status index has low selectivity for that condition because most rows match.

The optimizer may decide that scanning a large part of the table is more efficient than using the index.

Index usefulness depends on actual data distribution and query patterns.


98. What is an AUTO_INCREMENT column?

AUTO_INCREMENT automatically generates sequential numeric values.

id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY

It is commonly used for surrogate primary keys.


99. Natural key vs surrogate key?

A natural key uses meaningful business data, such as an email or registration number.

A surrogate key is an artificial identifier such as an auto-increment integer.

Many applications use surrogate IDs as primary keys while adding UNIQUE constraints to natural business identifiers.


100. What is the best way to answer MySQL scenario questions?

Do not immediately give SQL without understanding the requirement.

A good answer follows this process:

Understand the problem
↓
Check data volume
↓
Understand query pattern
↓
Check indexes
↓
Analyze EXPLAIN
↓
Design query
↓
Consider concurrency
↓
Check data integrity
↓
Measure performance

For example, if the interviewer asks:

"A table has 50 lakh rows and is slow. What would you do?"

A strong answer is:

"I would first identify which query is slow because table size alone does not tell me the problem. I would run EXPLAIN, check whether the WHERE and JOIN columns have appropriate indexes, check the number of rows scanned, avoid unnecessary SELECT *, review sorting and grouping, and check whether the API is trying to load too much data. If pagination uses very large offsets, I would consider keyset pagination."

This demonstrates practical database knowledge.


Frequently Asked MySQL Coding Interview Questions

101. Find employees with salary greater than average salary.

SELECT *
FROM employees
WHERE salary > (
    SELECT AVG(salary)
    FROM employees
);

102. Find duplicate records.

SELECT email, COUNT(*)
FROM users
GROUP BY email
HAVING COUNT(*) > 1;

103. Find the second highest salary.

SELECT MAX(salary)
FROM employees
WHERE salary < (
    SELECT MAX(salary)
    FROM employees
);

104. Find users who have no orders.

SELECT u.*
FROM users u
LEFT JOIN orders o
ON u.id = o.user_id
WHERE o.id IS NULL;

105. Find total sales by customer.

SELECT
    user_id,
    SUM(total_amount) AS total_sales
FROM orders
WHERE status = 'completed'
GROUP BY user_id;

106. Find customers with more than five orders.

SELECT
    user_id,
    COUNT(*) AS total_orders
FROM orders
GROUP BY user_id
HAVING COUNT(*) > 5;

107. Find top five highest-paid employees.

SELECT *
FROM employees
ORDER BY salary DESC
LIMIT 5;

108. Find the latest five orders.

SELECT *
FROM orders
ORDER BY created_at DESC
LIMIT 5;

109. Find monthly total sales.

SELECT
    YEAR(created_at) AS year,
    MONTH(created_at) AS month,
    SUM(total_amount) AS total
FROM orders
WHERE status = 'completed'
GROUP BY
    YEAR(created_at),
    MONTH(created_at)
ORDER BY year, month;

110. Find products that were never ordered.

SELECT p.*
FROM products p
LEFT JOIN order_items oi
ON p.id = oi.product_id
WHERE oi.product_id IS NULL;

Important MySQL Topics for PHP and Laravel Developers

If you are preparing for a backend development interview, you should be able to explain:

  • SQL basics
  • Primary and foreign keys
  • Constraints
  • Joins
  • Subqueries
  • UNION and UNION ALL
  • GROUP BY
  • HAVING
  • Aggregate functions
  • Indexes
  • Composite indexes
  • EXPLAIN
  • Query optimization
  • Transactions
  • ACID properties
  • Concurrency
  • Row locking
  • Deadlocks
  • Isolation levels
  • Normalization
  • Views
  • Stored procedures
  • Triggers
  • Window functions
  • Pagination
  • Large dataset optimization
  • Database security
  • Data integrity

How Should an Experienced Developer Answer MySQL Interview Questions?

For 3–5 years experience, interviewers usually expect more than definitions.

Instead of answering:

"An index makes queries faster."

A stronger answer is:

"An index provides an additional data structure that helps MySQL locate rows efficiently without scanning the whole table. I normally consider indexes on columns frequently used in WHERE, JOIN and ORDER BY conditions. However, I would not index every column because indexes consume storage and increase write overhead. I would analyze the actual query with EXPLAIN before deciding which index to add."

This answer demonstrates understanding rather than memorization.


Final Thoughts

MySQL interviews for experienced backend developers are not only about writing SELECT queries.

You should understand how relational databases work and how your decisions affect performance, concurrency and data integrity.

Important areas include indexes, joins, transactions, ACID properties, normalization, locking, EXPLAIN, query optimization and large dataset handling.

When preparing for interviews, practice SQL queries using real tables such as users, products, orders, payments and inventory.

Most importantly, understand why a query or database design works instead of simply memorizing syntax.

That practical understanding will help you answer both theoretical and real-world MySQL interview questions confidently.

Discussion

Questions and notes from readers. Comments appear after a short review.

No comments yet. Start the discussion.