SQL Interview Questions Freshers
SQL Interview Questions Freshers
What are the different types of SQL commands? (e.g., SELECT, INSERT, UPDATE, DELETE, DDL,
Query-Based Questions
Write a query to fetch all records from the Employees table where the salary is greater than 5000:
Write a query to find the second-highest salary from the Salaries table:
SELECT MAX(salary) FROM Salaries WHERE salary < (SELECT MAX(salary) FROM Salaries);
Scenario-Based Questions
How would you delete duplicate rows in a table while keeping one copy:
DELETE FROM table_name WHERE id NOT IN (SELECT MIN(id) FROM table_name GROUP BY
duplicate_column);
If a table has a million records, how would you optimize a query for better performance?
Write a query to fetch all employees whose names start with 'A' and end with 'n':
Write a query to find all employees whose salary is between 10,000 and 20,000:
What are Common Table Expressions (CTEs), and how are they used?
Practice writing queries in a real database environment (e.g., MySQL, PostgreSQL, SQL Server).