Anda di halaman 1dari 8

SQL QUERIES

Q1. Display all Employees from EMP table?


A. SELECT * FROM EMP;
Q2. Display all Departments from DEPT table?
A. SELECT * FROM DEPT;
Q3. Display the Name and Job for all Employees from EMP table?
A. SELECT ENAME, JOB FROM EMP;
Q4. Display the Name and Salary for all Employees from EMP
table?
A. SELECT ENAME, SAL FROM EMP;
Q5. Display the Name and Total Salary for all Employees from EMP
table?
A. SELECT ENAME, SAL + NVL (COMM,0) AS "TOTAL SALARY"
FROM EMP;
Q6. Display the Name and Annual Salary for all Employees from
EMP table?
A. SELECT ENAME, 12*(SAL + NVL (COMM,0)) AS "ANNUAL
SALARY" FROM EMP;
Q7. Display the Names of all the Employees who are working in
Department Number 10?
A. SELECT ENAME FROM EMP WHERE DEPTNO=10;
Q8. Display the Names of all the Employees who are working as
CLERKS and drawing a SALARY more than 3000?
A. SELECT ENAME FROM EMP WHERE JOB='CLERK' AND SAL >
3000;
Q9. Display the Employee number and Name who earn
Commission?
A. SELECT EMPID, ENAME FROM EMP WHERE COMM IS NOT NULL;
Q10. Display the Employee number and Name who do not earn
Commission?
A. SELECT EMPID, ENAME FROM EMP WHERE COMM IS NULL;
Q11. Display the names of the Employees who are working as
CLERKS, SALESMAN or ANALYST and drawing a SALARY more than
3000?

A. SELECT ENAME, JOB FROM EMP WHERE JOB = 'CLERK' OR JOB =


'SALESMAN' OR JOB = 'ANALYST' AND SAL>3000;
Q12. Display the names of the Employees who are working in the
company for the past 5 years?
A. SELECT ENAME FROM EMP WHERE TO_CHAR(SYSDATE, 'YYYY') TO_CHAR(HIREDATE, 'YYYY') > 5;
Q13. Display the list of employees who have joined the company
before 30-JUN-99 and after 31-DEC-99?
A. SELECT * FROM EMP WHERE HIREDATE < '30-JUN-1999' AND
TO HIREDATE > '31-DEC-1999';
Q14. Display Current Date?
A. SELECT SYSDATE FROM DUAL;
Q15. Display the list of all USERS in your database (use Catalog
table)?
A. SELECT USERNAME FROM ALL_USERS;
Q16. Display the names of all TABLES from Current Users?
A. SELECT TNAME FROM TAB;
Q17. Display the NAME of the Current User?
A. SHOW USER;
Q18. Display the Names of the Employees working in Department
Number 10 or 20 or 30 or Employees working as CLERKS,
SALESMAN, ANALYST?
A. SELECT ENAME FROM EMP WHERE DEPTNO IN (10,20,30) OR
JOB IN ('CLERK', 'SALESMAN', 'ANALYST');
OR
SELECT ENAME FROM EMP WHERE DEPTNO = 10 OR DEPTNO=20
OR DEPTNO=30 OR JOB = 'CLERK' OR JOB = 'SALESMAN' OR JOB
= 'ANALYST';
Q19. Display the Names of Employees whose Name starts with
alphabet 'S'?
A. SELECT ENAME FROM EMP WHERE ENAME LIKE 'S%';
Q20. Display the Names of Employees whose Name ends with
alphabet 'S'?
A. SELECT ENAME FROM EMP WHERE ENAME LIKE '%S';
Q21. Display the Names of Employees whose Names have 'A' as
second alphabet in their Names?

A. SELECT ENAME FROM EMP WHERE ENAME LIKE '_A%';


Q22. Select the Names of Employees whose Name is exactly 5
characters length?
A. SELECT ENAME FROM EMP WHERE LENGTH(ENAME)=5;
Q23. Display the Names of Employees who are not working as
MANAGERS?
A. SELECT ENAME FROM EMP WHERE JOB NOT IN ('MANAGER');
Q24. Display the Names of Employees who are not working as
CLERKS or SALESMAN or ANALYST?
A. SELECT ENAME FROM EMP WHERE JOB NOT IN ('CLERK',
'SALESMAN', 'ANALYST');
Q25. Display all rows from EMP table. System should wait after
every screen full of information?
A. SET PAUSE ON;
SELECT * FROM EMP;
Q26. Display the TOTAL number of Employees working in the
company?
A. SELECT COUNT(*) FROM EMP;
Q27. Display the TOTAL SALARY being paid to the Employees?
A. SELECT SUM(SAL) FROM EMP;
Q28. Display the MAXIMUM SALARY from EMP Table?
A. SELECT MAX(SAL) FROM EMP;
Q29. Display the MINIMUM SALARY from EMP Table?
A. SELECT MIN(SAL) FROM EMP;
Q30. Display the AVERAGE SALARY from EMP Table?
A. SELECT AVG(SAL) FROM EMP;
Q31. Display the MAXIMUM SALARY being paid to a CLERK?
A. SELECT MAX(SAL) FROM EMP WHERE JOB='CLERK';
Q32. Display the MAXIMUM SALARY being paid to Department
Number 20?
A. SELECT MAX(SAL) FROM EMP WHERE DEPTNO=20;
Q33. Display the MINIMUM SALARY being paid to any SALESMAN?
A. SELECT MIN(SAL) FROM EMP WHERE JOB = 'SALESMAN';
Q34. Display the AVERAGE SALARY drawn by MANAGERS?

A. SELECT AVG(SAL) FROM EMP WHERE JOB='MANAGER';


Q35. Display the TOTAL SALARY drawn by ANALYST working in
Department Number 20?
A. SELECT SUM(SAL) FROM EMP WHERE JOB = 'ANALYST' AND
DEPTNO=20;
Q36. Display the Names of the Employee in ORDER of SALARY i.e.
the Name of the Employee earning the LOWEST SALARY
should appear first?
A. SELECT ENAME FROM EMP ORDER BY SAL;
Q37. Display the Names of the Employee in DESCENDING ORDER
of SALARY?
A. SELECT ENAME FROM EMP ORDER BY SAL DESC;
Q38. Display the Names of the Employee in order of Employee
Name?
A. SELECT ENAME FROM EMP ORDER BY ENAME;
Q39. Display the EMP NO, EMP NAME, SAL, DEPT NO and sort the
output, first based on NAME and within NAME by DEPTNO and
within DEPTNO by SAL?
A. SELECT EMPID, ENAME, SAL, DEPTNO FROM EMP ORDER BY
NAME, DEPTNO, SAL ;
Q40. Display the Name of the Employee along with their Annual
Salary. The Name of the Employee earning the Highest Salary
should appear first?
A. SELECT ENAME, SAL*12 AS 'ANNUAL SALARY' FROM EMP
ORDER BY SAL DESC;
Q41. Display the Name, Salary, HRA, PF, DA, Total Salary of each
Employee. The Output should be in the order of Total Salary,
HRA - 15% of Salary, DA - 10% of Salary, PF - 5% of Salary?
Note: Total Salary = SAL + HRA + DA - PF
A. SELECT ENAME, SAL,
SAL * (15/100) AS 'HRA',
SAL * (10/100) AS 'DA',
SAL * (5/100) AS 'PF',
SAL + SAL * (15/100) + SAL * (10/100) - SAL * (5/100)' AS
'TOTALSAL',
ORDER BY TOTALSAL, HRA, DA, PF;
Q42. Display the Department Numbers and Total number of
Employees working in each department?

A. SELECT DEPTNO, COUNT(DEPTNO) FROM EMP GROUP BY


DEPTNO;
Q43. Display the different JOBS and Total number of Employees
working in each JOB?
A. SELECT JOB, COUNT (JOB) FROM EMP GROUP BY JOB;
Q44. Display the Department Numbers and Total Salary for each
Department?
A. SELECT DEPTNO, SUM(SAL) FROM EMP GROUP BY DEPTNO;
Q45. Display the Department Numbers and Maximum Salary for
each Department?
A. SELECT DEPTNO, MAX(SAL) FROM EMP GROUP BY DEPTNO;
Q46. Display the various JOBS and TOTAL SALARY for each JOB?
A. SELECT JOB, SUM(SAL) FROM EMP GROUP BY JOB;
Q47. Display the Department Numbers with more than 3
Employees in each Department?
A. SELECT DEPTNO, COUNT(DEPTNO) FROM EMP
GROUP BY DEPTNO
HAVING COUNT(*) > 3;
Q48. Display the various Jobs along with Total Salary for each of
the jobs where
Total Salary is greater than 40000?
A. SELECT JOB, SUM(SAL) FROM EMP GROUP BY JOB HAVING
SUM(SAL) > 40000;
Q49. Display the various Jobs along with Total Number of
Employees in each Job. The output should contain only those
Jobs with more than 3 Employees?
A. SELECT JOB, COUNT(EMPNO) FROM EMP GROUP BY JOB HAVING
COUNT(JOB) > 3;
Q50. Display the Name of Employee who earns Maximum Salary?
A. SELECT ENAME FROM EMP WHERE SAL = (SELECT MAX(SAL)
FROM EMP);
Q51. Display the Employee Number and Name, working as CLERK
and earning
Highest Salary among CLERKS?
A. SELECT EMPID, ENAME FROM EMP WHERE JOB = 'CLERK' AND
SAL = (SELECT
MAX (SAL) WHERE JOB = 'CLERK');
Q52. Display the Names of SALESMAN who earns a SALARY more
than the HIGHEST SALARY of any CLERK?

A. SELECT ENAME FROM EMP WHERE JOB = 'SALESMAN' AND SAL >
(SELECT MAX(SAL) FROM EMP WHERE JOB='CLERK');
Q53. Display the Names of CLERKS who earn a SALARY more than
the LOWEST
SALARY of any SALESMAN?
A. SELECT ENAME FROM EMP WHERE JOB = 'CLERK' AND SAL >
(SELECT MIN(SAL) FROM EMP WHERE JOB = 'SALESMAN');
Q54. Display the Names of Employees who earn a SALARY greater
than that of JONES and SALARY less than that of SCOTT?
A. SELECT ENAME FROM EMP WHERE SAL > (SELECT SAL FROM
EMP WHERE ENAME='JONES') AND SAL < (SELECT SAL FROM EMP
WHERE ENAME = 'SCOTT');
Q55. Display the Names of Employees who earn HIGHEST SALARY
in their respective Departments?
A. SELECT ENAME, SAL, DEPTNO FROM EMP WHERE SAL = (SELECT
MAX(SAL) FROM EMP GROUP BY DEPTNO);
Q56. Display the Names of Employees who earn HIGHEST
SALARIES in their respective Jobs?
A. SELECT ENAME, SAL, JOB FROM EMP WHERE SAL = (SELECT
MAX(SAL) FROM EMP GROUP BY JOB);
Q57. Display the Names of Employees who work in ACCOUNTING
Department?
A. SELECT ENAME, DEPTNO, DNAME FROM EMP, DEPT WHERE
EMP.DEPTNO =
(SELECT
DEPTNO
FROM
DEPT
WHERE
DNAME='ACCOUNTING');
Q58. Display the Names of Employees who are working in
CHICAGO Department?
A. SELECT ENAME, LOC FROM EMP, DEPT WHERE DEPTNO =
(SELECT DEPTNO
FROM DEPT WHERE LOC = 'CHICAGO');
Q59. Display the Job Groups having TOTAL SALARY greater than
the MAXIMUM SALARY for MANAGERS?
A. SELECT JOB FROM EMP GROUP BY JOB HAVING SUM(SAL) >
(SELECT MAX(SAL) FROM EMP WHERE JOB = 'MANAGER');
Q60. Display the Names of Employees from Department Number
10 with SALARY
greater than that of ANY Employee working in
any other Department?
A. SELECT ENAME FROM EMP WHERE DEPTNO = 10 AND SAL >
ANY (SELECT MAX(SAL) FROM EMP WHERE DEPTNO != 10);

Q61. Display the Names of Employees from Department Number


10 with SALARY
greater than that of ALL Employees working
in any other Department?
A. SELECT ENAME FROM EMP WHERE DEPTNO = 10 AND SAL > ALL
(SELECT MAX(SAL) FROM EMP WHERE DEPTNO != 10);
Q62. Display the Names of Employees in UPPER CASE?
A. SELECT UPPER(ENAME) FROM EMP;
Q63. Display the Names of Employees in LOWER CASE?
A. SELECT LOWER(ENAME) FROM EMP;
Q64. Display the Names of Employees in PROPER CASE?
A. SELECT INITCAP(ENAME) FROM EMP;
Q65. Display the Length of a Name with appropriate function?
A. SELECT LENGTH('NAME') FROM DUAL;
Q66. Display the Length of all Employee Names?
A. SELECT LENGTH(ENAME) FROM EMP;
Q67. Concatenate Employee Names with Employee Number?
A. SELECT EMPID || EMPNO FROM EMP;
Q68. Use appropriate function and extract 2 characters starting
from 3rd Position
in the string 'ORACLE' i.e the output should
be AC?
A. SELECT SUBSTR ('ORACLE', 3, 2) FROM DUAL;