Six Very Important SQL Queries

 1. Select The Employee from Employee table with the highest salary

 SELECT Employee_Name FROM Employees
 WHERE SALARY = (SELECT MAX(Salary) FROM Employees);

2. Select All employees with same salary in Employee table:

Here, we use SELF JOIN:

SELECT * FROM Employee A, Employee B
WHERE A.Emp_ID <> B.Emp_ID 
AND A.Salary=B.Salary

3. SELECT the second Highest Salary from Employee table:


4. SELECT range of Employee based on ID:

SELECT * FROM Employees 
WHERE Emp_ID BETWEEN 1000 and 2000;

5. SELECT Employee_name, Highest Salary and Department:

SELECT EMP.Emp_Name, DEPT.Department_Name, EMP.Salary FROM Employees EMP
INNER JOIN Department DEPT 
ON EMP.EMP_ID=DEPT.EMP_ID
WHERE EMP.Salary IN (SELECT MAX(Salary) from Employees)

6. SELECT Highest Salary, Employee Name and DepartmentName from each department:

SELECT DEPT.Department_Name, EMP.Emp_Name, MAX(EMP.Salary) FROM 
Employees EMP INNER JOIN Department DEPT
ON EMP.EmpId=DEPT.EmpID
GROUP BY DEPT.Department_Name, EMP.Emp_Name;





Comments

Popular posts from this blog

Jenkins CICD in One Page

Why do we need a build tool?

Deutsche Bank Interview Questions - 2024