Basic SQL Interview Questions – Top Questions & Answers (2026 Guide)
To ace a basic SQL interview in 2026, you must master core commands like SELECT, JOIN, and GROUP BY. SQL (Structured Query Language) is the standard language for managing databases. This guide covers 30+ essential questions, from simple queries to complex data relationships, helping freshers land data-driven roles.
H2 – Basic Interview Questions (For Freshers)
1. What is SQL and why is it important?
Direct Answer: SQL stands for Structured Query Language. It is the standard programming language used to communicate with and manage Relational Database Management Systems (RDBMS). It allows users to create, retrieve, update, and delete data, making it essential for data analysis, web development, and business intelligence.
Detailed Explanation: Think of a database like a giant library of digital filing cabinets. SQL is the language you use to tell the librarian exactly which file you need. Without SQL, it would be nearly impossible to find specific information hidden in millions of rows of data.
- Example: Using SQL to find the total sales made by a specific store in January.
- Pro Tip: Mention that while there are different “flavors” of SQL (like MySQL, PostgreSQL, and SQL Server), the basic commands remain the same.
2. What is a Relational Database?
Direct Answer: A Relational Database is a type of database that stores data in structured tables with rows and columns. Tables are linked to each other using unique keys (Primary and Foreign keys), allowing for organized data storage and efficient querying.
Detailed Explanation: Instead of putting all your data into one massive, messy spreadsheet, you break it into smaller tables (like “Customers,” “Orders,” and “Products”).
- Real-World Scenario: In an e-commerce app, your “Customer ID” in the Customers table connects to the “Customer ID” in the Orders table. This way, you don’t have to type the customer’s address every time they buy something.
- Pro Tip: Use the term RDBMS (Relational Database Management System) to sound more professional.
3. What is the difference between DDL and DML?
Direct Answer: DDL (Data Definition Language) commands like CREATE, ALTER, and DROP define the database structure. DML (Data Manipulation Language) commands like SELECT, INSERT, UPDATE, and DELETE are used to manage the actual data stored inside those structures.
Detailed Explanation:
- DDL: Building the “filing cabinet” (The structure).
- DML: Putting “files” into the cabinet (The data).
- Example: Using
CREATE TABLEis DDL; usingINSERT INTOto add a new user is DML. - Pro Tip: Remember that DDL changes usually cannot be “undone” easily (they are auto-committed).
4. What is a Primary Key?
Direct Answer: A Primary Key is a unique identifier for each record in a table. It must contain unique values and cannot contain NULL values. Every table should ideally have one primary key to ensure data can be accurately identified.
- Real-World Scenario: Your Aadhaar number or Social Security Number acts as a Primary Key for the government’s database. No two people have the same one.
- Pro Tip: A primary key can be a single column (ID) or a combination of columns (Composite Key).
[Ad Placement Suggestion: Best SQL for Data Science Online Certification]
H2 – Intermediate Interview Questions
5. What is a JOIN and what are the different types?
Direct Answer: A JOIN clause is used to combine rows from two or more tables based on a related column between them. The main types are INNER JOIN (matching records in both), LEFT JOIN (all from left table, matches from right), RIGHT JOIN, and FULL JOIN.
Detailed Explanation: Imagine you have a list of “Students” and a list of “Library Books.”
- INNER JOIN: Shows only students who have borrowed a book.
- LEFT JOIN: Shows all students, even if they haven’t borrowed any books.
- Pro Tip: In most real-world jobs, LEFT JOIN is the most commonly used because you often want to see all your primary data regardless of matches.
6. What is the difference between WHERE and HAVING?
Direct Answer: The WHERE clause is used to filter individual rows before any grouping happens. The HAVING clause is used to filter groups after the GROUP BY clause has been applied.
- Code Example:
SQL
SELECT Department, COUNT(*)
FROM Employees
WHERE Salary > 50000
GROUP BY Department
HAVING COUNT(*) > 5;
- Real-World Scenario: You first filter for high-earning employees (WHERE), then you only show departments that have more than 5 of those employees (HAVING).
7. What is a NULL value?
Direct Answer: A NULL value represents missing or unknown data. It is not the same as a zero (0) or a blank space. To find NULL values, you must use the IS NULL or IS NOT NULL operators.
- Pro Tip: You cannot use
=to find NULL. WritingWHERE Salary = NULLwill return nothing! Always useIS NULL.
H2 – Advanced Interview Questions (For Experienced)
8. What are Indexes and why do we use them?
Direct Answer: An Index is a physical structure used to speed up the retrieval of data from a table. It works like an index at the back of a book; instead of reading every page to find a topic, you look at the index to find the exact page number.
Detailed Explanation: While indexes make searching faster, they make “writing” (INSERT/UPDATE) slower because the index must be updated too.
- Pro Tip: Only create indexes on columns that you search for frequently (like
emailorcustomer_id).
9. What is Database Normalization?
Direct Answer: Normalization is the process of organizing data to reduce redundancy (repetition) and improve data integrity. It involves dividing large tables into smaller ones and defining relationships between them (1NF, 2NF, 3NF).
- Example: Moving a “Manufacturer Address” into its own table instead of repeating it next to every “Product” entry.
- Pro Tip: Over-normalization can make queries complex. Modern “Big Data” systems sometimes use De-normalization for speed.
H2 – Scenario-Based / Practical Questions
10. How do you find the second-highest salary in an Employees table?
Direct Answer: You can use a subquery or the OFFSET clause.
SQL
SELECT MAX(Salary)
FROM Employees
WHERE Salary < (SELECT MAX(Salary) FROM Employees);
OR
SQL
SELECT Salary FROM Employees
ORDER BY Salary DESC
LIMIT 1 OFFSET 1;
11. What would you do if a query is running very slowly?
Direct Answer: 1. I would check if the columns in the WHERE or JOIN clauses are indexed. 2. I would use the EXPLAIN command to see the execution plan. 3. I would check if I am using SELECT * (bad) instead of specific column names (good).
H2 – Coding Questions
12. Write a query to find all customers whose name starts with ‘A’.
SQL
SELECT * FROM Customers
WHERE CustomerName LIKE 'A%';
- Explanation: The
%is a wildcard that represents any number of characters.
13. Write a query to count how many orders each customer placed.
SQL
SELECT CustomerID, COUNT(OrderID)
FROM Orders
GROUP BY CustomerID;
H2 – HR / Behavioral Questions
- “How do you handle a situation where you accidentally deleted data?”
- Strategy: Focus on accountability and solutions. “I would immediately inform my lead, check for recent backups, and use transaction logs or
ROLLBACKif the session was still open.”
- Strategy: Focus on accountability and solutions. “I would immediately inform my lead, check for recent backups, and use transaction logs or
- “Why did you choose to learn SQL?”
- Strategy: Talk about your passion for data-driven decision-making. “SQL is the foundation of almost every modern business application.”
H2 – Real Interview Tips to Crack the Interview
- Format Your Code: Even on a whiteboard, use proper indentation. It shows you are a clean coder.
- Say it Out Loud: Explain your logic while writing the query.
- Ask for Clarification: If an interviewer asks for “Active Users,” ask what defines an “active” user (Last login? Last purchase?).
- Mention AI Tools: In 2026, mention how you use AI to optimize queries, but emphasize that you understand the underlying logic.
H2 – Common Mistakes to Avoid
- *Using SELECT : It’s lazy and slow. Always list the columns you need.
- Forgetting GROUP BY: If you use an aggregate function (COUNT, SUM) with a normal column, you must use GROUP BY.
- Case Sensitivity: Remember that while SQL keywords aren’t case-sensitive, the data inside the tables often is!
H2 – Salary Insights (2026 General Range)
- Data Analyst (Entry Level): ₹4.5L – ₹7L per year.
- SQL Developer (Mid-Level): ₹8L – ₹15L per year.
- Database Administrator (Senior): ₹18L+ per year. (Note: These are estimates based on standard Indian IT benchmarks.)
H2 – Final Interview Preparation Checklist
- [ ] Practice the basic JOIN types.
- [ ] Understand Aggregate Functions (SUM, AVG, MIN, MAX).
- [ ] Know the difference between DELETE, TRUNCATE, and DROP.
- [ ] Practice at least 5 subqueries.
- [ ] Read our AWS certification interview questions.
CTA:
- Download PDF Version
- Start Your Interview Preparation Today
- Explore More Interview Guides
FAQ Section
Yes. Despite the rise of NoSQL, SQL remains the primary language for data analysis and is used by almost every major company in the world.
MySQL is an open-source system often used for web apps. SQL Server is a Microsoft product often used in large corporate environments. The syntax is very similar.
A Foreign Key is a column that links to a Primary Key in another table, creating a relationship between the two.

Leave a Reply