sql interview questions

25 Powerful SQL Interview Questions for Freshers

Essential SQL Interview Questions for Freshers

Are you preparing for your first SQL interview? SQL (Structured Query Language) is a fundamental skill for database roles, and knowing the right questions can make a real difference. In this guide, you’ll explore 50+ SQL interview questions and answers for freshers, with examples, explanations, and tips to impress your interviewer.

What is SQL?

SQL (Structured Query Language) is used to communicate with relational databases. It is essential for database management, data retrieval, updates, and more. It’s a core skill for backend developers, data analysts, data engineers, and more.

Top SQL Interview Questions and Answers for Freshers

Let’s break down the most frequently asked SQL interview questions for freshers, grouped by category for easier understanding.

Basic SQL Interview Questions

Q1. What is SQL?
  • SQL stands for Structured Query Language. It is used for storing, manipulating, and retrieving data in a relational database.
Q2. What are the different types of SQL statements?
  • DDL – Data Definition Language (CREATE, DROP)

  • DML – Data Manipulation Language (INSERT, UPDATE, DELETE)

  • DCL – Data Control Language (GRANT, REVOKE)

  • TCL – Transaction Control Language (COMMIT, ROLLBACK)

  • DQL – Data Query Language (SELECT)

Q3. What is a primary key?
  • A primary key is a unique identifier for a record in a table. It cannot have null or duplicate values.
Q4. What is a foreign key?
  • A foreign key is a field that creates a relationship between two tables. It references the primary key in another table.

2. SQL Query Interview Questions

 

Q5. How do you select all data from a table?
				
					SELECT * FROM table_name;

				
			
Q6. Write a query to get the top 5 salaries from a table.
				
					SELECT DISTINCT salary  
FROM employees  
ORDER BY salary DESC  
LIMIT 5;

				
			
Q7. What is the difference between WHERE and HAVING?
  • WHERE is used for filtering rows before grouping.

  • HAVING is used to filter data after grouping with GROUP BY.

Q8. How do you count the number of rows in a table?
				
					SELECT COUNT(*) FROM table_name;
				
			
Q9. What is the use of GROUP BY?
  • GROUP BY is used to group rows with the same values in specified columns.

3. Advanced SQL Interview Questions

 

Q10. Explain JOIN and its types.
  • A JOIN is used to combine rows from two or more tables.
    Types of joins:
  • INNER JOIN: Returns matching rows.

  • LEFT JOIN: Returns all rows from the left table and matched rows from the right.

  • RIGHT JOIN: Returns all rows from the right table and matched rows from the left.

  • FULL JOIN: Returns all rows when there is a match in one of the tables.

Q11. What is a subquery?
  • A subquery is a query within another SQL query, often used in WHERE or FROM clauses.

10 Practical SQL Query Examples

  • Here are 10 SQL query interview examples commonly asked to freshers:

 

1. Select employees with salary > 50,000
				
					SELECT * FROM employees WHERE salary > 50000;
				
			
2. Find total salary department-wise
				
					SELECT department, SUM(salary) FROM employees GROUP BY department;

				
			
3. Retrieve all employees from ‘HR’ or ‘Sales’
				
					SELECT * FROM employees WHERE department IN ('HR', 'Sales');

				
			
4. Count employees per department
				
					SELECT department, COUNT(*) FROM employees GROUP BY department;

				
			
5. List employees joined after 2020
				
					SELECT * FROM employees WHERE joining_date > '2020-01-01';

				
			
6. Get the highest salary
				
					SELECT MAX(salary) AS highest_salary FROM employees;

				
			
7. Use INNER JOIN on employee and department tables
				
					SELECT e.name, d.department_name  
FROM employees e  
INNER JOIN departments d ON e.department_id = d.id;

				
			
8. Get distinct job titles
				
					SELECT DISTINCT job_title FROM employees;

				
			
9. Update salary of a specific employee
				
					UPDATE employees SET salary = 70000 WHERE employee_id = 5;

				
			
10. Delete employees with no email address
				
					DELETE FROM employees WHERE email IS NULL;

				
			

Best Practices for SQL Interviews

  • Understand query logic: Know why a query works, not just how.

  • Read the schema carefully: Always understand table relationships before writing a query.

  • Avoid SELECT *: Use specific columns to improve performance.

  • Be ready for real-world scenarios: Practice joining tables and using aggregate functions.

FAQs: SQL Interview Questions for Freshers

 

Q1. Is SQL easy to learn for freshers?
  • Yes, SQL is beginner-friendly and widely used. Understanding basic commands like SELECT, INSERT, UPDATE, and DELETE can help freshers get started quickly.
Q2. What is the difference between DELETE, TRUNCATE, and DROP?
  • DELETE: Deletes specific rows; can be rolled back.

  • TRUNCATE: Deletes all rows; cannot be rolled back.

  • DROP: Removes the entire table.

Q3. How can I prepare for an SQL interview?
  • Practice SQL problems on platforms like LeetCode or HackerRank.

  • Understand schema diagrams.

  • Revise common SQL functions and commands.

  • Go through previous sql query interview questions.

Q4. Can I use SQL in data science or analytics roles?
  • Absolutely! SQL is essential for data cleaning, analysis, and reporting in both fields.
Q5. What are common mistakes in SQL interviews?
  • Not handling NULL values properly

  • Using incorrect JOINs

  • Forgetting GROUP BY with aggregate functions

  • Not understanding performance implications

Conclusion

 

Mastering SQL interview questions for freshers is the key to landing your first role in tech, data analysis, or backend development. With the right preparation, even beginners can confidently answer both sql query interview questions and real-world problems.

Practice these questions, write your own queries, and review results carefully. And don’t forget — understanding why each query works will always give you the edge in interviews.

👉 Read more tech interview blogs on Freshy Blog for smart preparation tips!

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *