We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2
SQL Interview Questions
This document contains a combined list of SQL questions extracted from the provided images, categorized for clarity.
Query Writing & Data Manipulation
1. Write a query to find the second highest salary in an employee table. 2. Fetch all employees whose names contain the letter "a" exactly twice. 3. How do you retrieve only duplicate records from a table? 4. Write a query to calculate the running total of sales by date. 5. Find employees who earn more than the average salary in their department. 6. Write a query to find the most frequently occurring value in a column. 7. Fetch records where the date is within the last 7 days from today. 8. Write a query to count how many employees share the same salary. 9. How do you fetch the top 3 records for each group in a table? 10.Retrieve products that were never sold (hint: use LEFT JOIN). 11. Retrieve customers who made their first purchase in the last 6 months. 12.How do you pivot a table to convert rows into columns? 13.Write a query to calculate the percentage change in sales month-over-month. 14.Find the median salary of employees in a table. 15.Fetch all users who logged in consecutively for 3 days or more. 16.Write a query to delete duplicate rows while keeping one occurrence. 17.Create a query to calculate the ratio of sales between two categories. 18.How would you implement a recursive query to generate a hierarchical structure? 19.Write a query to find gaps in sequential numbering within a table. 20.Split a comma-separated string into individual rows using SQL. 21.Rank products by sales in descending order for each region. 22.Fetch all employees whose salaries fall within the top 10% of their department. 23.Identify orders placed during business hours (e.g., 9 AM to 6 PM). 24.Write a query to get the count of users active on both weekdays and weekends. 25.Retrieve customers who made purchases across at least three different categories. 26.Write retention query in SQL. 27.Write year-on-year growth query in SQL. 28.Write a query for cumulative sum in SQL.
SQL Concepts & Definitions
29.Explain the order of execution of SQL clauses. 30.What is the difference between WHERE and HAVING clauses? 31.What is the use of the GROUP BY clause? 32.Explain all types of joins in SQL (e.g., INNER, LEFT, RIGHT, FULL OUTER). 33.What are triggers in SQL? 34.What is a stored procedure in SQL? 35.Explain all types of window functions (e.g., RANK, ROW_NUMBER, DENSE_RANK, LEAD, LAG). 36.What is the difference between DELETE and TRUNCATE commands? 37.What are the differences between DML (Data Manipulation Language), DDL (Data Definition Language), and DCL (Data Control Language)? 38.What are aggregate functions and when are they used? Provide examples. 39.Which is generally faster: CTE (Common Table Expression) or Subquery? Why? 40.What are constraints in SQL? List different types of constraints. 41.What are Keys in SQL? Explain different types (Primary, Foreign, Unique, etc.). 42.Explain different types of Operators in SQL. 43.What are Views in SQL? 44.What is the difference between VARCHAR and NVARCHAR data types? (Similarly, CHAR vs NCHAR?) 45.What is an index in SQL? Explain its purpose and different types. 46.List and explain the different types of relationships in SQL databases (One-to-One, One-to-Many, Many-to-Many). 47.Differentiate between UNION and UNION ALL operators. 48.How many types of clauses are there in SQL? (This might refer to main clauses like SELECT, FROM, WHERE, etc.) 49.What is the difference between a Primary Key and a Secondary Key (or Alternate Key)? 50.What is the difference between a Function and a Stored Procedure in SQL? 51.Can variables be used in views? 52.What are the limitations of using views?