Top 15 SQL Interview Questions And Answers – Employee Table | Part – 1

Hello and welcome to Test Automation Central! This tutorial is entirely focused on SQL Interview Questions and Answers, with a specific emphasis on the employee’s table. Instead of conventional slides or presentations, we’ll take a hands-on approach and provide live demos of various SQL queries. Whether you’re a backend developer, full-stack engineer, or automation specialist, SQL knowledge is vital in today’s interviews. So, without any delay, let’s jump right in and get started!

Top 15 SQL interview Queries – Employee Table

Question #1
Retrieve all records from the “employees” table.

SELECT * FROM employees;

Question #2
Select specific columns “first_name” and “last_name” from the “employees” table.

SELECT first_name, last_name FROM employees;

Question #3
Filter records to find employees with a specific gender, e.g., “M” for males.

SELECT * FROM employees WHERE gender = 'M';

Question #4
Sort employees based on their hire date in ascending order.

SELECT * FROM employees ORDER BY hire_date;

Question #5
Retrieve employees who were hired on the first day of any month.

SELECT *
FROM employees
WHERE DAY(hire_date) = 1;

Question #6
Group employees based on their gender and find the count of employees in each gender category.

SELECT gender, COUNT(*) FROM employees GROUP BY gender;

Question #7
Find the earliest hire date among all employees.

SELECT MIN(hire_date) FROM employees;

Question #8
Find employees whose first name starts with “T”.

SELECT * FROM employees WHERE first_name LIKE 'T%';

Question #9
Update the hire date of an employee with a specific emp_no, e.g., set hire_date to ‘2023-01-01’ for emp_no 101.

UPDATE employees SET hire_date = '2023-01-01' WHERE emp_no = 10001;

Question #10
Find employees who were hired in the year 1995.

SELECT * FROM employees WHERE YEAR(hire_date) = 1995;

Question #11
Retrieve the names of employees who have the same first names.

SELECT first_name, COUNT(*) AS name_count
FROM employees
GROUP BY first_name
HAVING COUNT(*) > 1;

Question #12
Find the youngest and oldest employees from the “employees” table.

SELECT MIN(birth_date) AS youngest_employee, MAX(birth_date) AS oldest_employee
FROM employees;

Question #13
Retrieve employees who were hired on a Monday.

SELECT *
FROM employees
WHERE DAYOFWEEK(hire_date) = 2;

Question #14
Retrieve employees who were hired in the current year.

SELECT *
FROM employees
WHERE YEAR(hire_date) = YEAR(CURDATE());

Question #15
Delete the record from the “employees” table whose emp_no is before 10045.

DELETE FROM employees WHERE emp_no = 10045;

Share

Leave a Reply