Sql_Interview_Questions_Top_100
Sql_Interview_Questions_Top_100
DATA ENGINEERING
Raushan Kumar
SQL
INTERVIEW QUESTIONS
Raushan Kumar
https://www.linkedin.com/in/raushan-kumar-553154297/
100 DATA ENGINERING INTERVIEW SQL PROGRAMS
When preparing for a data engineering interview, it's crucial to
focus on SQL skills, as SQL is the backbone for most data
operations.
Below are 100 of the most important SQL programs or queries
that you should be familiar with, broken down into categories like
data retrieval, aggregation, joins, subqueries, window functions,
and more.
1. Basic Data Retrieval
1. Select all records from a table
SELECT * FROM employees;
1
8. Select distinct values from a column
SELECT DISTINCT department FROM employees;
2. Aggregation
11. Count the number of records
SELECT COUNT(*) FROM employees;
2
18. Find the total salary by department
SELECT department, SUM(salary) FROM employees GROUP BY
department;
3. Joins
21. Inner join two tables
SELECT e.first_name, d.department_name
FROM employees e
JOIN
departments d
ON e.department_id = d.department_id;
3
23. Right join two tables
SELECT e.first_name, d.department_name
FROM employees e
RIGHT JOIN
departments d
ON e.department_id = d.department_id;
4. Subqueries
26. Use a subquery in WHERE
SELECT * FROM employees WHERE department_id = (SELECT
department_id FROM departments WHERE department_name =
'HR');
4
27. Subquery with IN
SELECT * FROM employees WHERE department_id IN (SELECT
department_id FROM departments WHERE location = 'NY');
5. Window Functions
31. Rank employees by salary
SELECT first_name, salary, RANK() OVER (ORDER BY salary DESC) AS
salary_rank FROM employees;
5
33. Calculate moving average of salary
SELECT first_name, salary, AVG(salary) OVER (ORDER BY salary
ROWS BETWEEN 2 PRECEDING AND CURRENT ROW) AS
moving_avg FROM employees;
6
38. Nested CASE statement
SELECT first_name, salary,
CASE
WHEN salary > 70000 THEN
CASE WHEN department = 'HR' THEN 'HR High Salary'
ELSE 'Other High Salary'
END
ELSE 'Low Salary'
END AS salary_type
FROM employees;
7. String Functions
39. Concatenate two columns
SELECT CONCAT(first_name, ' ', last_name) AS full_name FROM
employees;
7
44. Replace substring within a string
SELECT REPLACE(first_name, 'John', 'Mike') FROM employees;
8
55. Find the difference in days between two dates
SELECT DATEDIFF(CURDATE(), hire_date) AS days_since_hired FROM
employees;
9. Data Modification
56. Insert data into a table
INSERT INTO employees (first_name, last_name, department, salary)
VALUES ('John', 'Doe', 'Engineering', 70000);
9
10. Temporary Tables and Advanced Concepts
61. Create and use a temporary table
CREATE TEMPORARY TABLE temp_employees AS SELECT * FROM
employees;
10
65. Handling NULL values using COALESCE
SELECT first_name, COALESCE(salary, 0) FROM employees;
11
12. Indexes and Optimization
71. Create an index on a column
CREATE INDEX idx_salary ON employees(salary);
12
78. Create a stored procedure
DELIMITER $$
CREATE PROCEDURE
get_employee_by_id(IN emp_id INT)
BEGIN
SELECT * FROM employees WHERE employee_id = emp_id;
END$$
DELIMITER ;
13
82. Find the difference between two tables (using
EXCEPT or NOT EXISTS)
SELECT * FROM employees
EXCEPT
SELECT * FROM contractors;
14
15. Optimization and Tuning
86. Use of EXPLAIN for query optimization:
EXPLAIN SELECT * FROM employees WHERE department = 'HR';
15
93. Incremental data loading (e.g., using timestamp):
SELECT * FROM raw_data WHERE timestamp > '2025-01-01';
16
98. Handling slowly changing dimensions:
UPDATE dim_customer SET address = 'New Address' WHERE
customer_id = 1;
17