0% found this document useful (0 votes)
194 views3 pages

Practice Ques: Select As From

The document contains 30 practice SQL queries to perform various operations on sample tables like selecting, filtering, aggregating, manipulating, and retrieving data. The queries cover concepts like aliases, aggregation, string manipulation, joins, sorting, filtering on conditions, grouping, subqueries and more. Solutions to common data retrieval and manipulation tasks using SQL are presented.

Uploaded by

ilakkiya R
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
194 views3 pages

Practice Ques: Select As From

The document contains 30 practice SQL queries to perform various operations on sample tables like selecting, filtering, aggregating, manipulating, and retrieving data. The queries cover concepts like aliases, aggregation, string manipulation, joins, sorting, filtering on conditions, grouping, subqueries and more. Solutions to common data retrieval and manipulation tasks using SQL are presented.

Uploaded by

ilakkiya R
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Practice Ques

1.Write an SQL query to fetch “FIRST_NAME” from Worker table using the alias name as <WORKER_NAME>.

select FIRST_NAME as WORKER_NAME from Worker ;

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

select upper(FIRST_NAME) from Worker ;

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

select distinct(DEPARTMENT) from Worker ;

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

select substring(FIRST_NAME,0,4) from Worker;

5. Write an SQL query to find the position of the alphabet (‘a’) in the first name
column ‘Amitabh’ from Worker table.

select charindex('a','amitabh') as matchposition;

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;

7. Write an SQL query that fetches the unique values of DEPARTMENT from Worker table
and prints its length.

select distinct len(DEPARTMENT) from worker;

8. 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;

9. Write an SQL query to print the FIRST_NAME and LAST_NAME from Worker table into a
single column COMPLETE_NAME. A space char should separate them.

select CONCAT(FIRST_NAME,' ',LAST_NAME) as COMPLETE_NAME from worker;

10. 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 ASC;

11. Write an SQL query to print details for Workers with the first name as “Vipul” and
“Satish” from Worker table

select * from worker where FIRST_NAME in ('Vipul','Satish');

12. 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');

13. Write an SQL query to print details of Workers with DEPARTMENT name as “Admin”.

select * from worker where DEPARTMENT='Admin';

14. Write an SQL query to print details of the Workers whose FIRST_NAME contains ‘a’.
select * from worker where FIRST_NAME like '%a%';

15. Write an SQL query to print details of the Workers whose FIRST_NAME ends with ‘a’.

select * from worker where FIRST_NAME like '%a';

16. 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';

17. 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 ;

18. Write an SQL query to print details of the Workers who have joined in Feb’2014.

Select * from Worker where year(JOINING_DATE) =1905 and month(JOINING_DATE)= 6;

19. Write an SQL query to fetch the count of employees working in the department
‘Admin’

Select count(WORKER_ID) from worker where DEPARTMENT='Admin';

20. Write an SQL query to fetch worker names with salaries >= 50000 and <= 100000.

Select concat(FIRST_NAME,LAST_NAME) as WORKER_NAME


from worker where salary between 5000 and 100000;

21. Write an SQL query to fetch the no. of workers for each department in the
descending order.

select count(WORKER_ID) as count_of_workers_by_department

from worker group by DEPARTMENT;

22.Write an SQL query to fetch the no. of workers for each department in the
descending order.

select count(WORKER_ID) as count_of_workers


from worker group by DEPARTMENT order by count_of_workers DESC;

23. Write an SQL query to print details of the Workers who are also Managers.

SELECT DISTINCT W.FIRST_NAME, T.WORKER_TITLE


FROM Worker W
INNER JOIN Title T
ON W.WORKER_ID = T.WORKER_REF_ID
AND T.WORKER_TITLE in ('Manager');

24. Write an SQL query to fetch duplicate records having matching data in some fields
of a table.

SELECT WORKER_TITLE, AFFECTED_FROM, COUNT(*)


FROM Title
GROUP BY WORKER_TITLE, AFFECTED_FROM
HAVING COUNT(*) > 1;

25. Write an SQL query to show only odd rows from a table.

SELECT * FROM Worker WHERE (WORKER_ID % 2) <> 0;

26. Write an SQL query to show only even rows from a table.

SELECT * FROM Worker WHERE (WORKER_ID % 2) = 0;


27. Write an SQL query to clone a new table from another table.

28.to get current date and time


select getdate();

29. Write an SQL query to show the top n (say 10) records of a table.

select top 5 * from worker order by salary;

30.

You might also like