SQL Interview Questions for Interns
1. Basic SELECT Query
You have a table called `employees` with the following structure:
+----+----------+------------+--------+
| id | name | department | salary |
+----+----------+------------+--------+
| 1 | Alice | HR | 50000 |
| 2 | Bob | IT | 60000 |
| 3 | Charlie | IT | 70000 |
| 4 | David | Finance | 65000 |
+----+----------+------------+--------+
Write a SQL query to retrieve the names and salaries of employees working in the IT
department.
Expected Output:
+--------+--------+
| name | salary |
+--------+--------+
| Bob | 60000 |
| Charlie| 70000 |
+--------+--------+
2. Using Aggregate Functions
Write a SQL query to find the average salary of employees in the `employees` table.
Expected Output Example:
+------------+
| avg_salary |
+------------+
| 61250 |
+------------+
3. Using GROUP BY and HAVING
Write a SQL query to count the number of employees in each department and display only
those departments where the number of employees is more than 1.
SQL Interview Questions for Interns
Expected Output Example:
+------------+------------+
| department | emp_count |
+------------+------------+
| IT | 2 |
+------------+------------+
4. Using JOIN
Consider two tables:
employees:
+----+----------+------------+
| id | name | department |
+----+----------+------------+
| 1 | Alice | HR |
| 2 | Bob | IT |
| 3 | Charlie | IT |
| 4 | David | Finance |
+----+----------+------------+
departments:
+------------+------------+
| name | location |
+------------+------------+
| HR | Building A |
| IT | Building B |
| Finance | Building C |
+------------+------------+
Write an SQL query to retrieve each employee's name along with their department's
location.
Expected Output Example:
+----------+------------+------------+
| name | department | location |
+----------+------------+------------+
| Alice | HR | Building A |
| Bob | IT | Building B |
| Charlie | IT | Building B |
| David | Finance | Building C |
SQL Interview Questions for Interns
+----------+------------+------------+
5. Using Subqueries
Write a SQL query to find the employees who have the highest salary in the `employees`
table.
Expected Output Example:
+---------+--------+
| name | salary |
+---------+--------+
| Charlie | 70000 |
+---------+--------+