SQL Queries Interview Question
SQL Interview Question
SQL Interview Question Welcome to My Tutorial Scan! in this post we will see the most commonly asked structured query language (SQL) queries in interviews. Firstly we start with very basic questions and then move to more complex SQL Interview questions.
Firstly we are taken two tables and understand the table structure and let’s see what’s question will be generated from the table.
Table: EmployeeDetail
Table: EmployeeSalary
SQL Queries Interview Question
1. Calculate the Count of Employees working on project P2?
Answer: Here, I will use count() function with the SQL where clause-
1 |
SELECT COUNT(*) FROM EmployeeSalary WHERE Project = 'P2'; |
2. How will be calculated those Employee Name whose having a salary greater than or equal to 38000 and less than 30000?
1 2 3 4 5 |
SELECT Name FROM EmployeeDetail WHERE EmpID IN (SELECT EmpID FROM EmpolyeeSalary WHERE Salary BETWEEN 38000 AND 30000); |
Explanation: First, we will use BETWEEN in the ‘where’ clause to return the empId of the employees with salary and then use it as a subquery to find the Name of the employee form EmployeeDetail table.
3. How to fetch and write a SQL query to a project-wise count of employees sorted by project’s count in ascending order.
1 2 3 4 |
SELECT Project, count(EmpID) EmpProjectCount FROM EmployeeSalary GROUP BY Project ORDER BY EmpProjectCount ASC; |
Resource
w3school