TOP 50 SQL queries for Interview Set-1

This is first set of TOP 50 SQL queries for Interview. Please NOTE that all questions and answers are based on our research and self-study.
Must Read:

— Q-1. Write an SQL query to fetch “FIRST_NAME” from the Worker table using the alias name as.

select first_name AS WORKER_NAME from the worker; 

— Q-2. Write an SQL query to fetch “FIRST_NAME” from Worker table in upper case.

select UPPER(first_name) from worker;

— Q-3. Write an SQL query to fetch unique values of DEPARTMENT from Worker table.

SELECT distinct department from worker;

— Q-4. Write an SQL query to print the first three characters of FIRST_NAME from Worker table.

select substring(first_name, 1, 3) from worker;

— Q-5. Write an SQL query to find the position of the alphabet (“b‟) in the first name column “Amitabh‟ from Worker table.

select INSTR(first_name, 'B') from worker where first_name = 'Amitabh';


— Q-6. Write an SQL query to print the FIRST_NAME from Worker table after removing white spaces from the right side.

select RTRIM(first_name) from worker;

— Q-7. Write an SQL query to print the DEPARTMENT from Worker table after removing white spaces from the left side.

select LTRIM(first_name) from worker;

— Q-8. Write an SQL query fetching DEPARTMENT’s unique values from Worker table and print its length.

select distinct department, LENGTH(department) from worker;

— Q-9. Write an SQL query to print the FIRST_NAME from Worker table after replacing „a‟ with „A‟.

select REPLACE(first_name, 'a', 'A') from worker;

— Q-10. Write an SQL query to print the FIRST_NAME and LAST_NAME from Worker table into a single column COMPLETE_NAME.

select CONCAT(first_name, ' ', last_name) AS COMPLETE_NAME from worker;

— Q-11. Write an SQL query to print all Worker details from the Worker table order by FIRST_NAME Ascending.

select * from worker ORDER by first_name;

— Q-12. Write an SQL query to print all Worker details from the Worker table order by

FIRST_NAME Ascending and DEPARTMENT Descending.
select * from worker order by first_name, department DESC;

— Q-13. Write an SQL query to print details for Workers with the first names “Vipul” and “Satish”
from Worker table.

select * from worker where first_name IN ('Vipul', 'Satish');

— Q-14. Write an SQL query to print details of workers excluding first names, “Vipul” and “Satish” from Worker table.

select * from worker where first_name NOT IN ('Vipul', 'Satish');

— Q-15. Write an SQL query to print details of Workers with DEPARTMENT name as “Admin*”.

select * from worker where department LIKE 'Admin%';

— Q-16. Write an SQL query to print details of the Workers whose FIRST_NAME contains “a‟.

select * from worker where first_name LIKE '%a%';

— Q-17. Write an SQL query to print details of the Workers whose FIRST_NAME ends with “a‟.

select * from worker where first_name LIKE '%a';

— Q-18. Write an SQL query to print details of the Workers whose FIRST_NAME ends with „h‟ and contains six alphabets.

select * from worker where first_name LIKE '_____h';

— Q-19. Write an SQL query to print details of the Workers whose SALARY lies between 100000 and 500000.

select * from worker where salary between 100000 AND 500000;

— Q-20. Write an SQL query to print details of the Workers who have joined in Feb‟2014.

select * from worker where YEAR(joining_date) = 2014
AND MONTH(joining_date) = 02;

— Q-21. Write an SQL query to fetch the count of employees working in the department “Admin‟.

select department, count(*) from worker where department = 'Admin';

— Q-22. Write an SQL query to fetch worker full names with salaries >= 50000 and <= 100000.

select concat(first_name, ' ', last_name) from worker
where salary between 50000 and 100000;

— Q-23. Write an SQL query to fetch the no. of workers for each department in the descending order.

select department, count(worker_id) AS no_of_worker
from worker group by department
ORDER BY no_of_worker desc;

— Q-24. Write an SQL query to print details of the Workers who are also Managers.

select w.* from worker as w inner join title as t on
w.worker_id = t.worker_ref_id where t.worker_title ='Manager';

— Q-25. Write an SQL query to fetch number (more than 1) of same titles in the ORG of different types.

select worker_title, count(*) as count from title group by worker_title having count > 1;

TOP 50 SQL queries TOP 50 SQL queries TOP 50 SQL queries TOP 50 SQL queries TOP 50 SQL queries

Leave a Reply

Your email address will not be published. Required fields are marked *