Top 30 SQL queries asked in 2022 interviews solved by me !
Top 30 SQL queries asked in 2022 interviews solved by me !
sql 1
use ORG;
CREATE TABLE EmployeeInfo (
EMP_ID INT NOT NULL PRIMARY KEY,
EMPF_NAME CHAR(25),
EMPL_NAME CHAR(25),
DEPARTMENT VARCHAR(50),
PROJECT VARCHAR(25),
ADDRES VARCHAR(25),
DOB DATE,
GENDER VARCHAR(25)
);
INSERT INTO EmployeeInfo
(EMP_ID, EMPF_NAME, EMPL_NAME, DEPARTMENT,PROJECT, ADDRES,DOB,GENDER)
VALUES
(1, 'Manager','2022-05-01',500000),
(2, 'Exicutive','2022-05-02',750000),
(3, 'Manager','2022-05-01',900000),
(2, 'Lead','2022-05-02',850000),
(1, 'Exicutive','2022-05-01',300000);
--Q2. Write a query to fetch the number of employees working in the department ‘HR’.
--Q4. Write a query to retrieve the first four characters of EmpLname from the
EmployeeInfo table.
--Q5. Write a query to fetch only the place name(string before brackets) from the
Address column of EmployeeInfo table.
--Q6. Write a query to create a new table which consists of data and structure copied
from the other table.
SELECT*FROM NEWTABLE;
--Q7. Write q query to find all the employees whose salary is between 50000 to 100000.
--Q8. Write a query to find the names of employees that begin with ‘S’.
--Q.10 Q10. Write a query to retrieve the EmpFname and EmpLname in a single column as
“FullName”.
--The first name and the last name must be separated with space.
--Q11. Write a query find number of employees whose DOB is between 02/05/1965 to
31/12/1975 and are grouped according to gender.
SELECT COUNT(*) ,GENDER FROM EmployeeInfo WHERE DOB BETWEEN '1965-05-02' AND
'1975-12-31' GROUP BY GENDER;
--Q12. Write a query to fetch all the records from the EmployeeInfo table ordered by
--EmpLname in descending order and Department in the ascending order.
--Q13. Write a query to fetch details of employees whose EmpLname ends with an
alphabet ‘A’ and contains five alphabets.
...gment course programing\SQL_practice top 30 questions.sql 3
SELECT * FROM EmployeeInfo WHERE EMPF_NAME LIKE '%____A';
--Q14. Write a query to fetch details of all employees excluding the employees with
first names,
--“Sanjay” and “Sonia” from the EmployeeInfo table.
--Q15. Write a query to fetch details of employees with the address as “DELHI(DEL)”.
--Q16. Write a query to fetch all employees who also hold the managerial position.
--Q18. Write a query to calculate the even and odd records from a table.
--Q19. Write a SQL query to retrieve employee details from EmployeeInfo table who have
a date of joining in the EmployeePosition table.
--Q20. Write a query to retrieve two minimum and maximum salaries from the
EmployeePosition table.
--Q21. Write a query to find the Nth highest salary from the table without using TOP/
limit keyword.
...gment course programing\SQL_practice top 30 questions.sql 4
SELECT DISTINCT SALARY,EmpPosition FROM EmployeePosition E1 WHERE 1>=(SELECT DISTINCT
COUNT(SALARY) FROM EmployeePosition E2 WHERE E1.Salary<=E2.Salary);
--Q23. Write a query to retrieve the list of employees working in the same department.
--Q24. Write a query to retrieve the last 3 records from the EmployeeInfo table.
--Q25. Write a query to find the third-highest salary from the EmpPosition table.
select top 1 Salary from(select top 3 Salary from EmployeePosition order by salary
desc) as emp order by salary asc;
--Q26. Write a query to display the first and the last record from the EmployeeInfo
table.
--Q28. Write a query to retrieve Departments who have less than 2 employees working
in it.
--Q29. Write a query to retrieve EmpPostion along with total salaries paid for each
of them.
--Q30. Write a query to fetch 50% records from the EmployeeInfo table.