SlideShare a Scribd company logo
2
Most read
3
Most read
7
Most read
SQL 
Top 40 SQL Queries For Testers 
1.Display employee number and total salary for each employee 
select empno,sal+comm 
from emp; 
2.Display the names of employees whose name starts with alphabetS 
select ename 
from emp 
where ename like 'S%'; 
3.Display the names of employees whose names have sencond 
alphabet A in their names 
select ename 
from emp 
where ename like '_S%'; 
4.Display employee name and department name for each employee 
select ename,dname 
from emp e,dept d 
where e.deptno=d.deptno; 
5.Display employee number,name and location of the department in 
which he is working 
select empno,ename,loc 
from emp e,dept d 
where e.detpno=d.deptno; 
6.Display ename,dname even if there no employees working in a 
particular department(use outer join) 
select ename,dname 
from emp e,dept d 
where e.deptno(+)=d.deptno; 
http://seleniumtemporary.blogspot.in/2014/09/top-40-sql-queries-for-testers.html Page 1
SQL 
7.select ename if ename exists more than once 
select distinct(ename) 
from emp e 
where ename in (select ename from emp where e.empno<>empno); 
8.Display the dept no with highest annual remuneration bill as 
compensation 
select deptno,sum(sal) 
from emp 
group by deptno having sum(sal)=(select max(sum(sal)) from emp group by 
deptno); 
9.List out the lowest paid employees working for each manager, 
exclude any groups where min sal is less than 1000 sort the output by 
sal 
select e.ename,e.mgr,e.sal 
from emp e 
where sal in (select min(sal) from emp where mgr=e.mgr) and 
e.sal>1000 order by sal; 
10.Display current date 
select sysdate 
from dual; 
11. Display various jobs along with total salary for each of the 
job where total salary is greater than 40000? 
select job,sum(sal) 
from emp 
group by job having sum(sal)>40000; 
12.Display the name of employee who earn Highest Salary? 
select ename, sal 
from emp 
where sal>=(select max(sal) from emp ); 
http://seleniumtemporary.blogspot.in/2014/09/top-40-sql-queries-for-testers.html Page 2
SQL 
13. Display the employee Number and name for employee working as 
clerk and earning highest salary among the clerks? 
select ename,empno 
from emp 
where sal=(select max(sal) from emp wherejob='CLERK') and job='CLERK' ; 
14. Display the employee names who are Working in Chicago? 
select e.ename,d.loc 
from emp e,dept d 
where e.deptno=d.deptno and d.loc='CHICAGO'; 
15. Display the job groups having Total Salary greater than the 
maximum salary for Managers? 
select job ,sum(sal) 
from emp 
group by job having sum(sal) >(select max(sal) from emp where 
job='MANAGER'); 
16. Display the names of employees from department number 10 with 
salary greater than that of ANY employee working in other 
departments? 
select ename,deptno 
from emp 
where sal>any(select min(sal) from emp where deptno!=10 group by 
deptno) and deptno=10 ; 
17. Display the names of employees from department number 10 with 
salary greater than that of ALL employee working in other 
departments? 
select ename,deptno 
from emp 
where sal>all(select max(sal) from emp where deptno!=10 group by deptno) 
and deptno=10 ; 
http://seleniumtemporary.blogspot.in/2014/09/top-40-sql-queries-for-testers.html Page 3
SQL 
18. Display the names of employees in Upper Case? 
select upper(ename) 
from emp; 
19. Display the names of employees in Lower Case? 
select Lower(ename) 
from emp; 
20. Display the length of all the employee names? 
select length(ename) 
from emp; 
21.Display the name of employee Concatinate with Employee 
Number? 
select ename||' '||empno 
from emp; 
22. Display the information from the employee table . where ever job 
Manager is found it should be displayed as Boss? 
select ename ,replace(job,'MANAGER','BOSS') 
from emp; 
23. Display those who are not managers? 
select ename 
from emp 
where job!='MANAGER'; 
24.Display the details of those employees who are in sales 
department and grade is 3? 
select e.ename,d.dname,grade 
from emp e,dept d ,salgrade 
where e.deptno=d.deptno and dname='SALES' and grade=3; 
http://seleniumtemporary.blogspot.in/2014/09/top-40-sql-queries-for-testers.html Page 4
SQL 
25. Display those department whose name start with"S" while 
location name ends with "K"? 
select e.ename,d.loc 
from emp e ,dept d 
where d.loc like('%K') and ename like('S%'); 
26. Display those employees whose salary is more than 3000 after 
giving 20% increment? 
select ename,sal,(sal+(sal*0.20)) 
from emp 
where (sal+(sal*0.20))>3000; 
27. Display employee name,dept name,salary,and commission for 
those sal in between 2000 to 5000 while location is Chicago? 
Select e.ename,d.dname,e.sal,e.comm 
from emp e,dept d 
where e.deptno=d.deptno and sal between 2000 and 5000; 
28. Display those employees whose salary is greater than his 
managers salary? 
Select e.ename,e.sal,e1.ename,e1.sal 
from emp e,e1 
where e.mgr=e1.empno and e.sal>e1.sal; 
29. Display the grade and employees name for the deptno 10 or 30 
but grade is not 4 while joined the company before 31-DEC-82? 
select ename,grade,deptno,sal 
from emp ,salgrade 
where ( grade,sal) in ( select grade,sal from salgrade,emp where sal between 
losal and hisal) 
and grade!=4 and deptno in (10,30) and hiredate<'31-Dec-82'; 
http://seleniumtemporary.blogspot.in/2014/09/top-40-sql-queries-for-testers.html Page 5
SQL 
30. Display those employees whose manager name is Jones? 
select e.ename Superior,e1.ename Subordinate 
from emp e,e1 
where e.empno=e1.mgr and e.ename='JONES'; 
31. Delete those employees who joined the company before 31-Dec- 
82 while their department Location is New York or Chicago? 
select e.ename,e.hiredate,d.loc 
from emp e,dept d 
where e.deptno=d.deptno and hiredate<'31-Dec-82' and d.loc in('NEW 
YORK','CHICAGO'); 
32. List out all the employee names ,job,salary,grade and deptname 
for every one in a company except 'CLERK' . Sort on salary display the 
highest salary? 
select e.ename ,e.job,e.sal,d.dname ,grade 
from emp e,salgrade,dept d 
where (e.deptno=d.deptno and e.sal between losal and hisal ) 
order by e.sal desc; 
33.Display employee name,sal,comm and netpay for those employees 
whose netpay is greater than or equal to any other employee salary of 
the company? 
select ename,sal,NVL(comm,0),sal+NVL(comm,0) 
from emp 
where sal+NVL(comm,0) >any (select e.sal from emp e ); 
34. Display those employees whose salary is less than his manager 
but more than salary of other managers? 
select e.ename sub,e.sal 
from emp e,e1,dept d 
where e.deptno=d.deptno and e.mgr=e1.empno and e.sal<e1.sal and e.sal 
>any (select e2.sal from emp e2,e,dept d1 
where e.mgr=e2.empno and d1.deptno=e.deptno); 
http://seleniumtemporary.blogspot.in/2014/09/top-40-sql-queries-for-testers.html Page 6
SQL 
35. Delete those records from emp table whose deptno not available 
in dept table? 
delete from emp e 
where e.deptno not in (select deptno from dept); 
36. Display those enames whose salary is out of grade available in 
salgrade table? 
select empno,sal 
from emp 
where sal<(select min(LOSAL) from salgrade ) 
OR sal>(select max(hisal) from salgrade); 
37.Display those employees who joined in the company in the month 
of Dec? 
Select empno,ename 
from emp 
where trim(to_char(hiredate,'Mon'))=trim('DEC'); 
38. Delete those records where no of employees in particular 
department is less than 3? 
Delete from emp 
where deptno in (select deptno from emp group by deptno having count(*) 
<3 ; 
39. Display empno,ename,deptno from emp table. Instead of display 
department numbers display the related department name(Use 
decode function)? 
select empno,ename,deptno,Decode(deptno,10,'ACCOUNTING' 
,20,'RESEARCH',30,'SALES','OPERATIONS')DName 
from emp; 
http://seleniumtemporary.blogspot.in/2014/09/top-40-sql-queries-for-testers.html Page 7
SQL 
40. Display those employees whose salary is odd value? 
select ename ,sal 
from emp 
where mod(sal,2)!=0; 
41.Display the Second maximum salary from the table using 
subquery. 
select max(salary) 
from Employee 
where salary NOT IN (select max(salary) from Employee); 
42.Display the Second maximum salary from the table using 
subquery. 
select TOP 1 salary from ( select TOP 2 salary from employees order by salary 
desc) as emp 
order by salary asc 
http://seleniumtemporary.blogspot.in/2014/09/top-40-sql-queries-for-testers.html Page 8

More Related Content

DOCX
Complex queries in sql
DOC
80 different SQL Queries with output
PDF
Data Visualization with Tableau - by Knowledgebee Trainings
PDF
Predictive Modelling
DOC
54024405 project-report-banking-management-system
DOC
Sql queires
PPTX
Understanding SQL Trace, TKPROF and Execution Plan for beginners
PPTX
Api testing
Complex queries in sql
80 different SQL Queries with output
Data Visualization with Tableau - by Knowledgebee Trainings
Predictive Modelling
54024405 project-report-banking-management-system
Sql queires
Understanding SQL Trace, TKPROF and Execution Plan for beginners
Api testing

What's hot (20)

PPT
Sql query [select, sub] 4
DOCX
SQL-RDBMS Queries and Question Bank
DOC
SQL practice questions set - 2
DOC
Sql queries with answers
PDF
PPTX
Sql operator
PPT
SQL subquery
PPT
Sql operators & functions 3
DOCX
All questions
PPT
PL/SQL Introduction and Concepts
PPTX
SUBQUERIES.pptx
PPTX
Sql subquery
PDF
Unix commands in etl testing
PPTX
Aggregate function
PPT
Single-Row Functions in orcale Data base
PDF
[APJ] Common Table Expressions (CTEs) in SQL
 
PPT
Aggregate functions
PPT
SQL Tutorial - Basic Commands
PPT
Including Constraints -Oracle Data base
Sql query [select, sub] 4
SQL-RDBMS Queries and Question Bank
SQL practice questions set - 2
Sql queries with answers
Sql operator
SQL subquery
Sql operators & functions 3
All questions
PL/SQL Introduction and Concepts
SUBQUERIES.pptx
Sql subquery
Unix commands in etl testing
Aggregate function
Single-Row Functions in orcale Data base
[APJ] Common Table Expressions (CTEs) in SQL
 
Aggregate functions
SQL Tutorial - Basic Commands
Including Constraints -Oracle Data base
Ad

Similar to Top 40 sql queries for testers (20)

DOC
21390228-SQL-Queries.doc
PDF
Orcl sql queries
PDF
Sql queries
PDF
Apurv Gupta, BCA ,Final year , Dezyne E'cole College
PDF
Simran kaur,BCA Final Year 2015
DOCX
Hands on Assignment for retrieving data using the SQL SELECT statement.docx
PDF
Vishwajeet Sikhwal ,BCA,Final Year 2015
PDF
Divyansh Mehta,BCA Final Year 2015 ,Dezyne E'cole College
PDF
Nikhil Khandelwal BCA 3rd Year
PPT
Chinabankppt
PDF
Vijay Kumar
PDF
SQL Top 10 Interview QnA By Rishabh Mishra in Hindi.pdf
PDF
Priyanka Bhatia.BCA Final year 2015
PDF
Pooja Bijawat,Bachelor Degree in Computer Application
PDF
Basic Sql Handouts
PPT
PPT
Sub queries
PPTX
Complex Queries using MYSQL00123211.pptx
PPT
Les02 (restricting and sorting data)
PPT
21390228-SQL-Queries.doc
Orcl sql queries
Sql queries
Apurv Gupta, BCA ,Final year , Dezyne E'cole College
Simran kaur,BCA Final Year 2015
Hands on Assignment for retrieving data using the SQL SELECT statement.docx
Vishwajeet Sikhwal ,BCA,Final Year 2015
Divyansh Mehta,BCA Final Year 2015 ,Dezyne E'cole College
Nikhil Khandelwal BCA 3rd Year
Chinabankppt
Vijay Kumar
SQL Top 10 Interview QnA By Rishabh Mishra in Hindi.pdf
Priyanka Bhatia.BCA Final year 2015
Pooja Bijawat,Bachelor Degree in Computer Application
Basic Sql Handouts
Sub queries
Complex Queries using MYSQL00123211.pptx
Les02 (restricting and sorting data)
Ad

Recently uploaded (20)

DOC
field study for teachers graduating samplr
PDF
Prostaglandin E2.pdf orthoodontics op kharbanda
PPTX
1751884730-Visual Basic -Unitj CS B.pptx
PPTX
Sports and Dance -lesson 3 powerpoint presentation
PDF
Manager Resume for R, CL & Applying Online.pdf
PPTX
Your Guide to a Winning Interview Aug 2025.
PPTX
Definition and Relation of Food Science( Lecture1).pptx
PPTX
OnePlus 13R – ⚡ All-Rounder King Performance: Snapdragon 8 Gen 3 – same as iQ...
PPTX
The Stock at arrangement the stock and product.pptx
DOCX
mcsp232projectguidelinesjan2023 (1).docx
PDF
Why Today’s Brands Need ORM & SEO Specialists More Than Ever.pdf
PPTX
DPT-MAY24.pptx for review and ucploading
PPTX
ESD MODULE-5hdbdhbdbdbdbbdbdbbdndbdbdbdbbdbd
PPTX
A slide for students with the advantagea
PDF
シュアーイノベーション採用ピッチ資料|Company Introduction & Recruiting Deck
PPTX
Job-opportunities lecture about it skills
PDF
Biography of Mohammad Anamul Haque Nayan
PDF
L-0018048598visual cloud book for PCa-pdf.pdf
PDF
APNCET2025RESULT Result Result 2025 2025
PPTX
Nervous_System_Drugs_PPT.pptxXXXXXXXXXXXXXXXXX
field study for teachers graduating samplr
Prostaglandin E2.pdf orthoodontics op kharbanda
1751884730-Visual Basic -Unitj CS B.pptx
Sports and Dance -lesson 3 powerpoint presentation
Manager Resume for R, CL & Applying Online.pdf
Your Guide to a Winning Interview Aug 2025.
Definition and Relation of Food Science( Lecture1).pptx
OnePlus 13R – ⚡ All-Rounder King Performance: Snapdragon 8 Gen 3 – same as iQ...
The Stock at arrangement the stock and product.pptx
mcsp232projectguidelinesjan2023 (1).docx
Why Today’s Brands Need ORM & SEO Specialists More Than Ever.pdf
DPT-MAY24.pptx for review and ucploading
ESD MODULE-5hdbdhbdbdbdbbdbdbbdndbdbdbdbbdbd
A slide for students with the advantagea
シュアーイノベーション採用ピッチ資料|Company Introduction & Recruiting Deck
Job-opportunities lecture about it skills
Biography of Mohammad Anamul Haque Nayan
L-0018048598visual cloud book for PCa-pdf.pdf
APNCET2025RESULT Result Result 2025 2025
Nervous_System_Drugs_PPT.pptxXXXXXXXXXXXXXXXXX

Top 40 sql queries for testers

  • 1. SQL Top 40 SQL Queries For Testers 1.Display employee number and total salary for each employee select empno,sal+comm from emp; 2.Display the names of employees whose name starts with alphabetS select ename from emp where ename like 'S%'; 3.Display the names of employees whose names have sencond alphabet A in their names select ename from emp where ename like '_S%'; 4.Display employee name and department name for each employee select ename,dname from emp e,dept d where e.deptno=d.deptno; 5.Display employee number,name and location of the department in which he is working select empno,ename,loc from emp e,dept d where e.detpno=d.deptno; 6.Display ename,dname even if there no employees working in a particular department(use outer join) select ename,dname from emp e,dept d where e.deptno(+)=d.deptno; http://seleniumtemporary.blogspot.in/2014/09/top-40-sql-queries-for-testers.html Page 1
  • 2. SQL 7.select ename if ename exists more than once select distinct(ename) from emp e where ename in (select ename from emp where e.empno<>empno); 8.Display the dept no with highest annual remuneration bill as compensation select deptno,sum(sal) from emp group by deptno having sum(sal)=(select max(sum(sal)) from emp group by deptno); 9.List out the lowest paid employees working for each manager, exclude any groups where min sal is less than 1000 sort the output by sal select e.ename,e.mgr,e.sal from emp e where sal in (select min(sal) from emp where mgr=e.mgr) and e.sal>1000 order by sal; 10.Display current date select sysdate from dual; 11. Display various jobs along with total salary for each of the job where total salary is greater than 40000? select job,sum(sal) from emp group by job having sum(sal)>40000; 12.Display the name of employee who earn Highest Salary? select ename, sal from emp where sal>=(select max(sal) from emp ); http://seleniumtemporary.blogspot.in/2014/09/top-40-sql-queries-for-testers.html Page 2
  • 3. SQL 13. Display the employee Number and name for employee working as clerk and earning highest salary among the clerks? select ename,empno from emp where sal=(select max(sal) from emp wherejob='CLERK') and job='CLERK' ; 14. Display the employee names who are Working in Chicago? select e.ename,d.loc from emp e,dept d where e.deptno=d.deptno and d.loc='CHICAGO'; 15. Display the job groups having Total Salary greater than the maximum salary for Managers? select job ,sum(sal) from emp group by job having sum(sal) >(select max(sal) from emp where job='MANAGER'); 16. Display the names of employees from department number 10 with salary greater than that of ANY employee working in other departments? select ename,deptno from emp where sal>any(select min(sal) from emp where deptno!=10 group by deptno) and deptno=10 ; 17. Display the names of employees from department number 10 with salary greater than that of ALL employee working in other departments? select ename,deptno from emp where sal>all(select max(sal) from emp where deptno!=10 group by deptno) and deptno=10 ; http://seleniumtemporary.blogspot.in/2014/09/top-40-sql-queries-for-testers.html Page 3
  • 4. SQL 18. Display the names of employees in Upper Case? select upper(ename) from emp; 19. Display the names of employees in Lower Case? select Lower(ename) from emp; 20. Display the length of all the employee names? select length(ename) from emp; 21.Display the name of employee Concatinate with Employee Number? select ename||' '||empno from emp; 22. Display the information from the employee table . where ever job Manager is found it should be displayed as Boss? select ename ,replace(job,'MANAGER','BOSS') from emp; 23. Display those who are not managers? select ename from emp where job!='MANAGER'; 24.Display the details of those employees who are in sales department and grade is 3? select e.ename,d.dname,grade from emp e,dept d ,salgrade where e.deptno=d.deptno and dname='SALES' and grade=3; http://seleniumtemporary.blogspot.in/2014/09/top-40-sql-queries-for-testers.html Page 4
  • 5. SQL 25. Display those department whose name start with"S" while location name ends with "K"? select e.ename,d.loc from emp e ,dept d where d.loc like('%K') and ename like('S%'); 26. Display those employees whose salary is more than 3000 after giving 20% increment? select ename,sal,(sal+(sal*0.20)) from emp where (sal+(sal*0.20))>3000; 27. Display employee name,dept name,salary,and commission for those sal in between 2000 to 5000 while location is Chicago? Select e.ename,d.dname,e.sal,e.comm from emp e,dept d where e.deptno=d.deptno and sal between 2000 and 5000; 28. Display those employees whose salary is greater than his managers salary? Select e.ename,e.sal,e1.ename,e1.sal from emp e,e1 where e.mgr=e1.empno and e.sal>e1.sal; 29. Display the grade and employees name for the deptno 10 or 30 but grade is not 4 while joined the company before 31-DEC-82? select ename,grade,deptno,sal from emp ,salgrade where ( grade,sal) in ( select grade,sal from salgrade,emp where sal between losal and hisal) and grade!=4 and deptno in (10,30) and hiredate<'31-Dec-82'; http://seleniumtemporary.blogspot.in/2014/09/top-40-sql-queries-for-testers.html Page 5
  • 6. SQL 30. Display those employees whose manager name is Jones? select e.ename Superior,e1.ename Subordinate from emp e,e1 where e.empno=e1.mgr and e.ename='JONES'; 31. Delete those employees who joined the company before 31-Dec- 82 while their department Location is New York or Chicago? select e.ename,e.hiredate,d.loc from emp e,dept d where e.deptno=d.deptno and hiredate<'31-Dec-82' and d.loc in('NEW YORK','CHICAGO'); 32. List out all the employee names ,job,salary,grade and deptname for every one in a company except 'CLERK' . Sort on salary display the highest salary? select e.ename ,e.job,e.sal,d.dname ,grade from emp e,salgrade,dept d where (e.deptno=d.deptno and e.sal between losal and hisal ) order by e.sal desc; 33.Display employee name,sal,comm and netpay for those employees whose netpay is greater than or equal to any other employee salary of the company? select ename,sal,NVL(comm,0),sal+NVL(comm,0) from emp where sal+NVL(comm,0) >any (select e.sal from emp e ); 34. Display those employees whose salary is less than his manager but more than salary of other managers? select e.ename sub,e.sal from emp e,e1,dept d where e.deptno=d.deptno and e.mgr=e1.empno and e.sal<e1.sal and e.sal >any (select e2.sal from emp e2,e,dept d1 where e.mgr=e2.empno and d1.deptno=e.deptno); http://seleniumtemporary.blogspot.in/2014/09/top-40-sql-queries-for-testers.html Page 6
  • 7. SQL 35. Delete those records from emp table whose deptno not available in dept table? delete from emp e where e.deptno not in (select deptno from dept); 36. Display those enames whose salary is out of grade available in salgrade table? select empno,sal from emp where sal<(select min(LOSAL) from salgrade ) OR sal>(select max(hisal) from salgrade); 37.Display those employees who joined in the company in the month of Dec? Select empno,ename from emp where trim(to_char(hiredate,'Mon'))=trim('DEC'); 38. Delete those records where no of employees in particular department is less than 3? Delete from emp where deptno in (select deptno from emp group by deptno having count(*) <3 ; 39. Display empno,ename,deptno from emp table. Instead of display department numbers display the related department name(Use decode function)? select empno,ename,deptno,Decode(deptno,10,'ACCOUNTING' ,20,'RESEARCH',30,'SALES','OPERATIONS')DName from emp; http://seleniumtemporary.blogspot.in/2014/09/top-40-sql-queries-for-testers.html Page 7
  • 8. SQL 40. Display those employees whose salary is odd value? select ename ,sal from emp where mod(sal,2)!=0; 41.Display the Second maximum salary from the table using subquery. select max(salary) from Employee where salary NOT IN (select max(salary) from Employee); 42.Display the Second maximum salary from the table using subquery. select TOP 1 salary from ( select TOP 2 salary from employees order by salary desc) as emp order by salary asc http://seleniumtemporary.blogspot.in/2014/09/top-40-sql-queries-for-testers.html Page 8