You are on page 1of 88

Difference between Smoke & Sanity Software Testing

Smoke Testing: Software Testing done to ensure that whether the build can be accepted for through
software testing or not. Basically, it is done to check the stability of the build received for software
testing.

Sanity testing: After receiving a build with minor changes in the code or functionality, a subset of
regression test cases are executed that to check whether it rectified the software bugs or issues and
no other software bug is introduced by the changes. Sometimes, when multiple cycles of regression
testing are executed, sanity testing of the software can be done at later cycles after through
regression test cycles. If we are moving a build from staging / testing server to production server,
sanity testing of the software application can be done to check that whether the build is sane enough
to move to further at production server or not.

Difference between Smoke & Sanity Software Testing:

Smoke testing is a wide approach where all areas of the software application are tested
without getting into too deep. However, a sanity software testing is a narrow regression
testing with a focus on one or a small set of areas of functionality of the software application.
The test cases for smoke testing of the software can be either manual or automated.
However, a sanity test is generally without test scripts or test cases.
Smoke testing is done to ensure whether the main functions of the software application are
working or not. During smoke testing of the software, we do not go into finer details. However,
sanity testing is a cursory software testing type. It is done whenever a quick round of software
testing can prove that the software application is functioning according to business / functional
requirements.
Smoke testing of the software application is done to check whether the build can be accepted
for through software testing. Sanity testing of the software is to ensure whether the
requirements are met or not.
Question 1: SQL Query to find second highest salary of Employee

select MAX(Salary) from Employee WHERE Salary NOT IN (select


MAX(Salary) from Employee );
Question 2: SQL Query to find Max Salary from each department.

SELECT DeptID, MAX(Salary) FROM Employee GROUP BY DeptID.


SELECT DeptName, MAX(Salary) FROM Employee e RIGHT JOIN Department d ON e.DeptId =
d.DeptID GROUP BY DeptName;
Question 3: Write SQL Query to display the current date.

SELECT GetDate();

Question 4: Write an SQL Query to check whether date passed to Query is the date of given format
or not.

SELECT ISDATE('1/08/13') AS "MM/DD/YY";


Write an SQL Query to print the name of the distinct employee whose DOB is between 01/01/1960 to
31/12/1975.

SELECT DISTINCT EmpName FROM Employees WHERE DOB BETWEEN


01/01/1960 AND 31/12/1975;
Question 6: Write an SQL Query find number of employees according to gender whose DOB is
between 01/01/1960 to 31/12/1975.
SELECT COUNT(*), sex from Employees WHERE DOB BETWEEN '01/01/1960' AND
'31/12/1975' GROUP BY sex;
Question 7: Write an SQL Query to find an employee whose Salary is equal or greater than 10000.

SELECT EmpName FROM Employees WHERE Salary>=10000;


Question 8: Write an SQL Query to find name of employee whose name Start with M
SELECT * FROM Employees WHERE EmpName like 'M%';
find all Employee records containing the word "Joe", regardless of whether it was stored as JOE,
Joe, or joe.
SELECT * from Employees WHERE UPPER(EmpName) like '%JOE%';

SQL Queries Interview Questions and Answers on "SQL Select"


1. Get all employee details from the employee table

Select * from employee

2. Get First_Name,Last_Name from employee table

Select first_name, Last_Name from employee

3. Get First_Name from employee table using alias name Employee Name

Select first_name Employee Name from employee

4. Get First_Name from employee table in upper case

Select upper(FIRST_NAME) from EMPLOYEE

5. Get First_Name from employee table in lower case

Select lower(FIRST_NAME) from EMPLOYEE

6. Get unique DEPARTMENT from employee table

select distinct DEPARTMENT from EMPLOYEE

Don't Miss - SQL and Database theory Interview Questions

7. Select first 3 characters of FIRST_NAME from EMPLOYEE

Oracle Equivalent of SQL Server SUBSTRING is SUBSTR, Query : select

substr(FIRST_NAME,0,3) from employee

SQL Server Equivalent of Oracle SUBSTR is SUBSTRING, Query : select

substring(FIRST_NAME,1,3) from employee


MySQL Server Equivalent of Oracle SUBSTR is SUBSTRING. In MySQL start

position is 1, Query : select substring(FIRST_NAME,1,3) from employee

8. Get position of 'o' in name 'John' from employee table

Oracle Equivalent of SQL Server CHARINDEX is INSTR, Query : Select

instr(FIRST_NAME,'o') from employee where first_name='John'

SQL Server Equivalent of Oracle INSTR is CHARINDEX, Query: Select

CHARINDEX('o',FIRST_NAME,0) from employee where first_name='John'

MySQL Server Equivalent of Oracle INSTR is LOCATE, Query: Select

LOCATE('o',FIRST_NAME) from employee where first_name='John'

9. Get FIRST_NAME from employee table after removing white spaces from
right side

select RTRIM(FIRST_NAME) from employee

10. Get FIRST_NAME from employee table after removing white spaces from
left side

select LTRIM(FIRST_NAME) from employee

11. Get length of FIRST_NAME from employee table

Oracle,MYSQL Equivalent of SQL Server Len is Length , Query :select

length(FIRST_NAME) from employee

SQL Server Equivalent of Oracle,MYSQL Length is Len, Query :select

len(FIRST_NAME) from employee


12. Get First_Name from employee table after replacing 'o' with '$'

select REPLACE(FIRST_NAME,'o','$') from employee

13. Get First_Name and Last_Name as single column from employee table
separated by a '_'

Oracle Equivalent of MySQL concat is '||', Query : Select FIRST_NAME|| '_'

||LAST_NAME from EMPLOYEE

SQL Server Equivalent of MySQL concat is '+', Query : Select FIRST_NAME + '_'

+LAST_NAME from EMPLOYEE

MySQL Equivalent of Oracle '||' is concat, Query : Select

concat(FIRST_NAME,'_',LAST_NAME) from EMPLOYEE

14. Get FIRST_NAME ,Joining year,Joining Month and Joining Date from
employee table

SQL Queries in Oracle, Select FIRST_NAME, to_char(joining_date,'YYYY') JoinYear ,

to_char(joining_date,'Mon'), to_char(joining_date,'dd') from EMPLOYEE

SQL Queries in SQL Server, select SUBSTRING

(convert(varchar,joining_date,103),7,4) , SUBSTRING

(convert(varchar,joining_date,100),1,3) , SUBSTRING

(convert(varchar,joining_date,100),5,2) from EMPLOYEE

SQL Queries in MySQL, select year(joining_date),month(joining_date),

DAY(joining_date) from EMPLOYEE

15. Get all employee details from the employee table order by First_Name Ascending
Select * from employee order by FIRST_NAME asc
16. Get all employee details from the employee table order by First_Name
descending

Select * from employee order by FIRST_NAME desc

17. Get all employee details from the employee table order by First_Name Ascending
and Salary descending

Select * from employee order by FIRST_NAME asc,SALARY desc

"SQL Where Condition" Interview Questions


18. Get employee details from employee table whose employee name is John

Select * from EMPLOYEE where FIRST_NAME='John'

19. Get employee details from employee table whose employee name are John and
Roy

Select * from EMPLOYEE where FIRST_NAME in ('John','Roy')

20. Get employee details from employee table whose employee name are not John
and Roy

Select * from EMPLOYEE where FIRST_NAME not in ('John','Roy')

"SQL Wild Card Search" Interview Questions


21. Get employee details from employee table whose first name starts with 'J'

Select * from EMPLOYEE where FIRST_NAME like 'J%'

22. Get employee details from employee table whose first name contains 'o'

Select * from EMPLOYEE where FIRST_NAME like '%o%'

23. Get employee details from employee table whose first name ends with 'n'

Select * from EMPLOYEE where FIRST_NAME like '%n'


"SQL Pattern Matching" Interview Questions

24. Get employee details from employee table whose first name ends with 'n'
and name contains 4 letters

Select * from EMPLOYEE where FIRST_NAME like '___n' (Underscores)

25. Get employee details from employee table whose first name starts with 'J'
and name contains 4 letters

Select * from EMPLOYEE where FIRST_NAME like 'J___' (Underscores)

26. Get employee details from employee table whose Salary greater than
600000

Select * from EMPLOYEE where Salary >600000

27. Get employee details from employee table whose Salary less than 800000

Select * from EMPLOYEE where Salary <800000

28. Get employee details from employee table whose Salary between 500000
and 800000

Select * from EMPLOYEE where Salary between 500000 and 800000

29. Get employee details from employee table whose name is 'John' and
'Michael'

Select * from EMPLOYEE where FIRST_NAME in ('John','Michael')

30. Get employee details from employee table whose joining year is 2013

SQL Queries in Oracle, Select * from EMPLOYEE where

to_char(joining_date,'YYYY')='2013'
SQL Queries in SQL Server, Select * from EMPLOYEE where

SUBSTRING(convert(varchar,joining_date,103),7,4)='2013'

SQL Queries in MySQL, Select * from EMPLOYEE where year(joining_date)='2013'

31. Get employee details from employee table whose joining month is
January
SQL Queries in Oracle, Select * from EMPLOYEE where

to_char(joining_date,'MM')='01' or Select * from EMPLOYEE where

to_char(joining_date,'Mon')='Jan'

SQL Queries in SQL Server, Select * from EMPLOYEE where

SUBSTRING(convert(varchar,joining_date,100),1,3)='Jan'

SQL Queries in MySQL, Select * from EMPLOYEE where month(joining_date)='01'

32. Get employee details from employee table who joined before January 1st
2013
SQL Queries in Oracle, Select * from EMPLOYEE where JOINING_DATE

<to_date('01/01/2013','dd/mm/yyyy')

SQL Queries in SQL Server (Format - MM/DD/YYYY), Select * from EMPLOYEE

where joining_date <'01/01/2013'

SQL Queries in MySQL (Format - YYYY-DD-MM), Select * from EMPLOYEE where

joining_date <'2013-01-01'

33. Get employee details from employee table who joined after January 31st
SQL Queries in Oracle, Select * from EMPLOYEE where JOINING_DATE

>to_date('31/01/2013','dd/mm/yyyy')

SQL Queries in SQL Server and MySQL (Format - MM/DD/YYYY), Select * from

EMPLOYEE where joining_date >'01/31/2013'

SQL Queries in MySQL (Format - YYYY-DD-MM), Select * from EMPLOYEE where

joining_date >'2013-01-31'

35. Get Joining Date and Time from employee table

SQL Queries in Oracle, select to_char(JOINING_DATE,'dd/mm/yyyy hh:mi:ss') from

EMPLOYEE

SQL Queries in SQL Server, Select convert(varchar(19),joining_date,121) from

EMPLOYEE

SQL Queries in MySQL, Select CONVERT(DATE_FORMAT(joining_date,'%Y-%m-

%d-%H:%i:00'),DATETIME) from EMPLOYEE

36. Get Joining Date,Time including milliseconds from employee table

SQL Queries in Oracle, select to_char(JOINING_DATE,'dd/mm/yyyy HH:mi:ss.ff') from

EMPLOYEE . Column Data Type should be TimeStamp

SQL Queries in SQL Server, select convert(varchar,joining_date,121) from

EMPLOYEE
SQL Queries in MySQL, Select MICROSECOND(joining_date) from EMPLOYEE

37. Get difference between JOINING_DATE and INCENTIVE_DATE from


employee and incentives table

Select FIRST_NAME,INCENTIVE_DATE - JOINING_DATE from employee a inner join

incentives B on A.EMPLOYEE_ID=B.EMPLOYEE_REF_ID

38. Get database date

SQL Queries in Oracle, select sysdate from dual

SQL Queries in SQL Server, select getdate()

SQL Query in MySQL, select now()

39. Get names of employees from employee table who has '%' in Last_Name.
Tip : Escape character for special characters in a query.

SQL Queries in Oracle, Select FIRST_NAME from employee where Last_Name like

'%?%%'

SQL Queries in SQL Server, Select FIRST_NAME from employee where Last_Name

like '%[%]%'

SQL Queries in MySQL, Select FIRST_NAME from employee where Last_Name like

'%\%%'
40. Get Last Name from employee table after replacing special character with white
space

SQL Queries in Oracle, Select translate(LAST_NAME,'%',' ') from employee

SQL Queries in SQL Server and MySQL, Select REPLACE(LAST_NAME,'%',' ') from

employee

"SQL Group By Query" Interview Questions and Answers


41. Get department,total salary with respect to a department from employee table.

Select DEPARTMENT,sum(SALARY) Total_Salary from employee group by

department

42. Get department,total salary with respect to a department from employee table
order by total salary descending

Select DEPARTMENT,sum(SALARY) Total_Salary from employee group by

DEPARTMENT order by Total_Salary descending

SQL Queries Interview Questions and Answers on "SQL


Mathematical Operations using Group By"
43. Get department,no of employees in a department,total salary with respect
to a department from employee table order by total salary descending

Select DEPARTMENT,count(FIRST_NAME),sum(SALARY) Total_Salary from

employee group by DEPARTMENT order by Total_Salary descending

44. Get department wise average salary from employee table order by salary
ascending

select DEPARTMENT,avg(SALARY) AvgSalary from employee group by

DEPARTMENT order by AvgSalary asc


45. Get department wise maximum salary from employee table order by salary
ascending

select DEPARTMENT,max(SALARY) MaxSalary from employee group by

DEPARTMENT order by MaxSalary asc

46. Get department wise minimum salary from employee table order by salary
ascending

select DEPARTMENT,min(SALARY) MinSalary from employee group by

DEPARTMENT order by MinSalary asc

47. Select no of employees joined with respect to year and month from
employee table

SQL Queries in Oracle, select to_char (JOINING_DATE,'YYYY') Join_Year,to_char

(JOINING_DATE,'MM') Join_Month,count(*) Total_Emp from employee group by

to_char (JOINING_DATE,'YYYY'),to_char(JOINING_DATE,'MM')

SQL Queries in SQL Server, select datepart (YYYY,JOINING_DATE)

Join_Year,datepart (MM,JOINING_DATE) Join_Month,count(*) Total_Emp from

employee group by datepart(YYYY,JOINING_DATE), datepart(MM,JOINING_DATE)

SQL Queries in MySQL, select year (JOINING_DATE) Join_Year,month

(JOINING_DATE) Join_Month,count(*) Total_Emp from employee group by

year(JOINING_DATE), month(JOINING_DATE)

48. Select department,total salary with respect to a department from employee


table where total salary greater than 800000 order by Total_Salary descending
Select DEPARTMENT,sum(SALARY) Total_Salary from employee group by

DEPARTMENT having sum(SALARY) >800000 order by Total_Salary desc

49. Select employee details from employee table if data exists in incentive
table ?

select * from EMPLOYEE where exists (select * from INCENTIVES)

Explanation : Here "exists" statement helps us to do the job of If statement. Main


query will get executed if the sub query returns at least one row. So we can consider
the sub query as "If condition" and the main query as "code block" inside the If
condition. We can use any SQL commands (Joins, Group By , having etc) in sub
query. This command will be useful in queries which need to detect an event and do
some activity.

50. How to fetch data that are common in two query results ?
select * from EMPLOYEE where EMPLOYEE_ID INTERSECT select * from

EMPLOYEE where EMPLOYEE_ID < 4

Explanation : Here "INTERSECT" command is used to fetch data that are common
in 2 queries. In this example, we had taken EMPLOYEE table in both the queries.We
can apply INTERSECT command on different tables. The result of the above query
will return employee details of "ROY" because, employee id of ROY is 3, and both
query results have the information about ROY.

51. Get Employee ID's of those employees who didn't receive incentives
without using sub query ?
select EMPLOYEE_ID from EMPLOYEE

MINUS

select EMPLOYEE_REF_ID from INCENTIVES

Explanation : To filter out certain information we use MINUS command. What


MINUS Command odes is that, it returns all the results from the first query, that are
not part of the second query. In our example, first three employees received the
incentives. So query will return employee id's 4 to 8.

52. Select 20 % of salary from John , 10% of Salary for Roy and for other 15 %
of salary from employee table
SELECT FIRST_NAME, CASE FIRST_NAME WHEN 'John' THEN SALARY * .2 WHEN

'Roy' THEN SALARY * .10 ELSE SALARY * .15 END "Deduced_Amount" FROM

EMPLOYEE

Explanation : Here, we are using "SQL CASE" statement to achieve the desired
results. After case statement, we had to specify the column on which filtering is
applied. In our case it is "FIRST_NAME". And in then condition, specify the name of
filter like John, Roy etc. To handle conditions outside our filter, use else block where
every one other than John and Roy enters.

53. Select Banking as 'Bank Dept', Insurance as 'Insurance Dept' and Services
as 'Services Dept' from employee table

SQL Queries in Oracle, SELECT distinct DECODE (DEPARTMENT, 'Banking', 'Bank

Dept', 'Insurance', 'Insurance Dept', 'Services', 'Services Dept') FROM EMPLOYEE

SQL Queries in SQL Server and MySQL, SELECT case DEPARTMENT when 'Banking'

then 'Bank Dept' when 'Insurance' then 'Insurance Dept' when 'Services' then 'Services

Dept' end FROM EMPLOYEE

Explanation : Here "DECODE" keyword is used to specify the alias name. In oracle
we had specify, Column Name followed by Actual Name and Alias Name as
arguments. In SQL Server and MySQL, we can use the earlier switch case
statements for alias names.

54. Delete employee data from employee table who got incentives in incentive
table

delete from EMPLOYEE where EMPLOYEE_ID in (select EMPLOYEE_REF_ID from

INCENTIVES)

Explanation : Trick about this question is that we can't delete data from a table
based on some condition in another table by joining them. Here to delete multiple
entries from EMPLOYEE table, we need to use Subquery. Entries will get deleted
based on the result of Subquery.

55. Insert into employee table Last Name with " ' " (Single Quote - Special
Character)
Tip - Use another single quote before special character

Insert into employee (LAST_NAME) values ('Test''')

56. Select Last Name from employee table which contain only numbers

Select * from EMPLOYEE where lower(LAST_NAME)=upper(LAST_NAME)

Explanation : In order to achieve the desired result, we use "ASCII" property of the
database. If we get results for a column using Lower and Upper commands, ASCII of
both results will be same for numbers. If there is any alphabets in the column, results
will differ.

57. Write a query to rank employees based on their incentives for a month

select FIRST_NAME,INCENTIVE_AMOUNT,DENSE_RANK() OVER (PARTITION BY

INCENTIVE_DATE ORDER BY INCENTIVE_AMOUNT DESC) AS Rank from

EMPLOYEE a, INCENTIVES b where a.EMPLOYEE_ID=b.EMPLOYEE_REF_ID

Explanation : In order to rank employees based on their rank for a month,


"DENSE_RANK" keyword is used. Here partition by keyword helps us to sort the
column with which filtering is done. Rank is provided to the column specified in the
order by statement. The above query ranks employees with respect to their
incentives for a given month.

58. Update incentive table where employee name is 'John'

update INCENTIVES set INCENTIVE_AMOUNT='9000' where

EMPLOYEE_REF_ID=(select EMPLOYEE_ID from EMPLOYEE where

FIRST_NAME='John' )

Explanation : We need to join Employee and Incentive Table for updating the
incentive amount. But for update statement joining query wont work. We need to use
sub query to update the data in the incentive table. SQL Query is as shown below.

59. Select first_name, incentive amount from employee and incentives table for
those employees who have incentives
Select FIRST_NAME,INCENTIVE_AMOUNT from employee a inner join incentives B

on A.EMPLOYEE_ID=B.EMPLOYEE_REF_ID

60. Select first_name, incentive amount from employee and incentives table for those
employees who have incentives and incentive amount greater than 3000

Select FIRST_NAME,INCENTIVE_AMOUNT from employee a inner join incentives B

on A.EMPLOYEE_ID=B.EMPLOYEE_REF_ID and INCENTIVE_AMOUNT >3000

61. Select first_name, incentive amount from employee and incentives table for all
employes even if they didn't get incentives

Select FIRST_NAME,INCENTIVE_AMOUNT from employee a left join incentives B on

A.EMPLOYEE_ID=B.EMPLOYEE_REF_ID

62. Select first_name, incentive amount from employee and incentives table for all
employees even if they didn't get incentives and set incentive amount as 0 for those
employees who didn't get incentives.

SQL Queries in Oracle, Select FIRST_NAME,nvl(INCENTIVE_AMOUNT,0) from

employee a left join incentives B on A.EMPLOYEE_ID=B.EMPLOYEE_REF_ID

SQL Queries in SQL Server, Select FIRST_NAME, ISNULL(INCENTIVE_AMOUNT,0)

from employee a left join incentives B on A.EMPLOYEE_ID=B.EMPLOYEE_REF_ID

SQL Queries in MySQL, Select FIRST_NAME, IFNULL(INCENTIVE_AMOUNT,0) from

employee a left join incentives B on A.EMPLOYEE_ID=B.EMPLOYEE_REF_ID

63. Select first_name, incentive amount from employee and incentives table for all
employees who got incentives using left join

SQL Queries in Oracle, Select FIRST_NAME,nvl(INCENTIVE_AMOUNT,0) from

employee a right join incentives B on A.EMPLOYEE_ID=B.EMPLOYEE_REF_ID

SQL Queries in SQL Server, Select FIRST_NAME, isnull(INCENTIVE_AMOUNT,0)

from employee a right join incentives B on A.EMPLOYEE_ID=B.EMPLOYEE_REF_ID


SQL Queries in MySQL, Select FIRST_NAME, IFNULL(INCENTIVE_AMOUNT,0) from

employee a right join incentives B on A.EMPLOYEE_ID=B.EMPLOYEE_REF_ID

64. Select max incentive with respect to employee from employee and incentives table
using sub query

SQL Queries in Oracle, select DEPARTMENT,(select

nvl(max(INCENTIVE_AMOUNT),0) from INCENTIVES where

EMPLOYEE_REF_ID=EMPLOYEE_ID) Max_incentive from EMPLOYEE

SQL Queries in SQL Server, select DEPARTMENT,(select

ISNULL(max(INCENTIVE_AMOUNT),0) from INCENTIVES where

EMPLOYEE_REF_ID=EMPLOYEE_ID) Max_incentive from EMPLOYEE

SQL Queries in SQL Server, select DEPARTMENT,(select IFNULL

(max(INCENTIVE_AMOUNT),0) from INCENTIVES where

EMPLOYEE_REF_ID=EMPLOYEE_ID) Max_incentive from EMPLOYEE

"Top N Salary" SQL Interview Questions and Answers


65. Select TOP 2 salary from employee table

SQL Queries in Oracle, select * from (select * from employee order by SALARY desc)

where rownum <3

SQL Queries in SQL Server, select top 2 * from employee order by salary desc

SQL Queries in MySQL, select * from employee order by salary desc limit 2

66. Select TOP N salary from employee table


SQL Queries in Oracle, select * from (select * from employee order by SALARY desc)

where rownum <N + 1

SQL Queries in SQL Server, select top N * from employee

SQL Queries in MySQL, select * from employee order by salary desc limit N

67. Select 2nd Highest salary from employee table

SQL Queries in Oracle, select min(salary) from (select * from (select * from employee

order by SALARY desc) where rownum <3)

SQL Queries in SQL Server, select min(SALARY) from (select top 2 * from employee)

SQL Queries in MySQL, select min(SALARY) from (select * from employee order by

salary desc limit 2) a

68. Select Nth Highest salary from employee table

SQL Queries in Oracle, select min(salary) from (select * from (select * from employee

order by SALARY desc) where rownum <N + 1)

SQL Queries in SQL Server, select min(SALARY) from (select top N * from employee)

SQL Queries in MySQL, select min(SALARY) from (select * from employee order by

salary desc limit N) a


"SQL Union" Query Interview Questions
69. Select First_Name,LAST_NAME from employee table as separate rows

select FIRST_NAME from EMPLOYEE union select LAST_NAME from EMPLOYEE

70. What is the difference between UNION and UNION ALL ?

Both UNION and UNION ALL is used to select information from structurally similar

tables. That means corresponding columns specified in the union should have same

data type. For example, in the above query, if FIRST_NAME is DOUBLE and

LAST_NAME is STRING above query wont work. Since the data type of both the

columns are VARCHAR, union is made possible. Difference between UNION and

UNION ALL is that , UNION query return only distinct values.

71. Write create table syntax for employee table


Oracle -CREATE TABLE EMPLOYEE (

EMPLOYEE_ID NUMBER,

FIRST_NAME VARCHAR2(20 BYTE),

LAST_NAME VARCHAR2(20 BYTE),

SALARY FLOAT(126),

JOINING_DATE TIMESTAMP (6) DEFAULT sysdate,

DEPARTMENT VARCHAR2(30 BYTE) )

SQL Server -CREATE TABLE EMPLOYEE(

EMPLOYEE_ID int NOT NULL,

FIRST_NAME varchar(50) NULL,

LAST_NAME varchar(50) NULL,

SALARY decimal(18, 0) NULL,

JOINING_DATE datetime2(7) default getdate(),

DEPARTMENT varchar(50) NULL)


72. Write syntax to delete table employee

DROP table employee;

73. Write syntax to set EMPLOYEE_ID as primary key in employee table

ALTER TABLE EMPLOYEE add CONSTRAINT EMPLOYEE_PK PRIMARY

KEY(EMPLOYEE_ID)

74. Write syntax to set 2 fields(EMPLOYEE_ID,FIRST_NAME) as primary key in


employee table

ALTER TABLE EMPLOYEE add CONSTRAINT EMPLOYEE_PK PRIMARY

KEY(EMPLOYEE_ID,FIRST_NAME)

75. Write syntax to drop primary key on employee table

Alter TABLE EMPLOYEE drop CONSTRAINT EMPLOYEE_PK;

76. Write Sql Syntax to create EMPLOYEE_REF_ID in INCENTIVES table as


foreign key with respect to EMPLOYEE_ID in employee table

ALTER TABLE INCENTIVES ADD CONSTRAINT INCENTIVES_FK FOREIGN KEY

(EMPLOYEE_REF_ID) REFERENCES EMPLOYEE(EMPLOYEE_ID)

77. Write SQL to drop foreign key on employee table

ALTER TABLE INCENTIVES drop CONSTRAINT INCENTIVES_FK;

78. Write SQL to create Orcale Sequence

CREATE SEQUENCE EMPLOYEE_ID_SEQ START WITH 0 NOMAXVALUE

MINVALUE 0 NOCYCLE NOCACHE NOORDER;

79. Write Sql syntax to create Oracle Trigger before insert of each row in
employee table
CREATE OR REPLACE TRIGGER EMPLOYEE_ROW_ID_TRIGGER

BEFORE INSERT ON EMPLOYEE FOR EACH ROW

DECLARE

seq_no number(12);

BEGIN

select EMPLOYEE_ID_SEQ.nextval into seq_no from dual ;

:new EMPLOYEE_ID :=seq_no;

END;

SHOW ERRORS;

80. Oracle Procedure81. Oracle View

An example oracle view script is given below

create view Employee_Incentive as select FIRST_NAME,max(INCENTIVE_AMOUNT)

INCENTIVE_AMOUNT from EMPLOYEE a, INCENTIVES b where

a.EMPLOYEE_ID=b.EMPLOYEE_REF_ID group by FIRST_NAME

82. Oracle materialized view - Daily Auto Refresh

CREATE MATERIALIZED VIEW Employee_Incentive

REFRESH COMPLETE

START WITH SYSDATE

NEXT SYSDATE + 1 AS

select FIRST_NAME,INCENTIVE_DATE,INCENTIVE_AMOUNT from EMPLOYEE a,

INCENTIVES b

where a.EMPLOYEE_ID=b.EMPLOYEE_REF_ID

83. Oracle materialized view - Fast Refresh on Commit


Create materialized view log for fast refresh. Following materialized view script wont get

executed if materialized view log doesn't exists

CREATE MATERIALIZED VIEW MAT_Employee_Incentive_Refresh

BUILD IMMEDIATE

REFRESH FAST ON COMMIT AS

select FIRST_NAME,max(INCENTIVE_AMOUNT) from EMPLOYEE a, INCENTIVES b

where a.EMPLOYEE_ID=b.EMPLOYEE_REF_ID group by FIRST_NAME

84. What is SQL Injection ?

SQL Injection is one of the the techniques uses by hackers to hack a website by

injecting SQL commands in data fields.

https://www.tutorialspoint.com/sql_certificate/subqueries_to_solve_queries_questions.htm

. Which of the following are the types of sub-queries?

A. Ordered sub-queries
B. Grouped sub-queries
C. Single row sub-queries
D. None of the above

Answer: C. A subquery is a complete query nested in the SELECT,FROM,


HAVING, or WHERE clause of another query.The subquery must be
enclosed in parentheses and have a SELECT and a FROM clause, at a
minimum. Single row sub-queries and multi-row sub-queries are the main
types of sub-queries

2.Which of the following is true about sub-queries?

A. They execute after the main query executes


B. They execute in parallel to the main query
C. The user can execute the main query and then, if wanted, execute the sub-
query
D. They execute before the main query executes.
Answer: D. The sub-query always executes before the execution of the
main query.Subqueries are completed first.The result of the subquery is
used as input for the outer query.

3.Which of the following is true about the result of a sub-query?

A. The result of a sub-query is generally ignored when executed.


B. The result of a sub-query doesn't give a result, it is just helpful in speeding up
the main query execution
C. The result of a sub-query is used by the main query.
D. The result of a sub-query is always NULL

Answer: C. Subqueries are completed first.The result of the subquery is


used as input for the outer query.

4.Which of the following clause is mandatorily used in a sub-


query?

A. SELECT
B. WHERE
C. ORDER BY
D. GROUP BY

Answer: A. A sub-query is just like any other query which has to start
with a SELECT clause. They are contained within an outer query.

5. Which of the following is a method for writing a sub-query in a


main query?

A. By using JOINS
B. By using WHERE clause
C. By using the GROUP BY clause
D. By writing a SELECT statement embedded in the clause of another SELECT
statement

Answer: D. A subquery is a complete query nested in the SELECT, FROM,


HAVING, or WHERE clause of another query.The subquery must be
enclosed in parentheses and have a SELECT and a FROM clause, at a
minimum.
6.In the given scenarios, which one would appropriately justify the
usage of sub-query?

A. When we need to sum up values


B. When we need to convert character values into date or number values
C. When we need to select rows from a table with a condition that depends on
the data from the same or different table.
D. None of the above

Answer: C.

7.In which of the following clauses can a sub-query be used?

A. HAVING
B. WHERE
C. FROM
D. All of the above

Answer: D. A sub-query is not different from a normal query. It can make


use of all the primary clauses of a SELECT statement.

8.Which of the following single-row operators can be used for


writing a sub-query?

A. >=
B. <
C. =
D. All of the above

Answer: D. Single-row operators include =, >, <, >=, <=, and <>.

9.Which of the following multi-row operators can be used with a


sub-query?

A. IN
B. ANY
C. ALL
D. All of the above
Answer: D. Multiple-row subqueries return more than one row of
results.Operators that can be used with multiple-row subqueries include
IN, ALL, ANY, and EXISTS.

10.What is true about the output obtained from a sub-query?

A. It remains in the buffer cache


B. It remains inside the sub-query and can be used later when needed
C. It is used to complete the outer (main) query
D. Both A and C

Answer: C. Subqueries are completed first.The result of the subquery is


used as input for the outer query.

11.You need to find the salaries for all the employees who have a
higher salary than the Vice President of a company 'ABC'.Which of
the following queries will give you the required result? (Consider
the table structure as given)

SQL> DESC employees


Name Null? Type
----------------------- -------- ----------------
EMPLOYEE_ID NOT NULL NUMBER(6)
FIRST_NAME VARCHAR2(20)
LAST_NAME NOT NULL VARCHAR2(25)
EMAIL NOT NULL VARCHAR2(25)
PHONE_NUMBER VARCHAR2(20)
HIRE_DATE NOT NULL DATE
JOB_ID NOT NULL VARCHAR2(10)
SALARY NUMBER(8,2)
COMMISSION_PCT NUMBER(2,2)
MANAGER_ID NUMBER(6)
DEPARTMENT_ID NUMBER(4)

A. SELECT first_name, last_name, salary


B. FROM employees
C. WHERE salary > (SELECT salary
D. FROM employees
E. WHERE job_id = 'VICE-PRESIDENT');
F. SELECT first_name, last_name, salary
G. FROM employees
H. WHERE salary = (SELECT salary
I. FROM employees
J. WHERE job_id = 'VICE-PRESIDENT');
K. SELECT first_name, last_name, salary
L. FROM employees
M. WHERE job_id = 'VICE-PRESIDENT');

N. None of the above

Answer: A. In the option 'A', the inner sub-query gives the VP's salary as
a result to the outer query.

12.What among the following is true about sub-queries?

A. Sub-queries can be written on either side of a comparison operator


B. Parenthesis is not mandatory for sub-queries
C. Single-row sub-queries can use multi-row operators but vice versa is not
possible
D. All of the above

Answer: A. Sub queries can be placed on left or right hand side of the
comparison operator depending on the query indentation and usability.

13. What will be the outcome of the following query? (Consider the
given table structure)

SQL> DESC employees


Name Null? Type
----------------------- -------- ----------------
EMPLOYEE_ID NOT NULL NUMBER(6)
FIRST_NAME VARCHAR2(20)
LAST_NAME NOT NULL VARCHAR2(25)
EMAIL NOT NULL VARCHAR2(25)
PHONE_NUMBER VARCHAR2(20)
HIRE_DATE NOT NULL DATE
JOB_ID NOT NULL VARCHAR2(10)
SALARY NUMBER(8,2)
COMMISSION_PCT NUMBER(2,2)
MANAGER_ID NUMBER(6)
DEPARTMENT_ID NUMBER(4)
SELECT first_name, last_name, salary
FROM employees
WHERE salary ANY (SELECT salary FROM employees);

A. It executes successfully giving the desired results


B. It executes successfully but does not give the desired results
C. It throws an ORA error
D. It executes successfully and gives two values for each row obtained in the
result set

Answer: C. Multi-row operators cannot be used in single-row sub-queries


and vice versa.

14.Which of the following is true about single-row sub-queries?

A. They give one result from the main query


B. They give only one row in the result set
C. They return only one row from the inner SELECT statement
D. They give multiple rows from the main (outer) query

Answer: C. A single-row subquery can return a maximum of one value.

15.What is true about multi-row sub-queries?

A. They can return more than one column as the result of the inner query
B. They return multiple rows in the main query but only a single result set in the
inner query
C. They return single row in the main query but multiple rows in the inner sub-
query
D. They return more than one row from the inner SELECT statement

Answer: D. Multi-column sub-queries return more than one column in


their result set, multi-row sub-queries return more than one row from the
inner query.

16.What among the following is true about single-row sub-


queries?
A. They return only one row
B. They use single-row operators
C. Both A and B
D. None of the above

Answer: C.

17.Which of the following operators cannot be used in a sub-


query?

A. AND
B. <
C. >
D. <>

Answer: A. Single-row operators include =, >, <, >=, <=, and <>. Multi-
row operators that can be used with multiple-row subqueries include IN,
ALL, ANY, and EXISTS.

Examine the exhibit and answer the questions 18 to 21 that follow.

18.You need to find out the names of all employees who belong to
the same department as the employee 'Jessica Butcher' who is in
department 100 and has an employee ID 40. Which of the following
queries will be correct?

A. SELECT first_name, last_name


B. FROM employees
C. WHERE last_name = 'Butcher'
D. And first_name = 'Jessica';
E. SELECT first_name, last_name
F. FROM employees
G. WHERE department =100;
H. SELECT first_name, last_name
I. FROM employees
J. WHERE department = (SELECT department
K. FROM employees
L. WHERE first_name = 'Jessica'
M. AND last_name = 'Butcher');
N. SELECT first_name, last_name
O. FROM employees
P. WHERE department = (SELECT department
Q. FROM employees
R. WHERE first_name = 'Jessica'
S. AND last_name = 'Butcher'
T. AND department = 100
U. AND employee_id = 40);

Answer: D. 'D' is more appropriate than 'C' because it filters on employee


id which is unique and ensures that the sub-query will return single row
only. 'C' can fail if there are more than one employee with the same first
and last name.

19.You need to find out the employees which belong to the


department of 'Jessica Butcher' and have salary greater than the
salary of 'Jessica Butcher' who has an employee ID of 40. Which of
the following queries will work?

A. SELECT first_name, last_name


B. FROM employees
C. WHERE last_name = 'Butcher'
D. AND first_name = 'Jessica'
E. AND salary > 10000;
F. SELECT first_name, last_name
G. FROM employees
H. WHERE department = 100;
I. SELECT first_name, last_name
J. FROM employees
K. WHERE department = (SELECT department
L. FROM employees
M. WHERE first_name = 'Jessica'
N. AND last_name = 'Butcher'
O. AND employee_id = 40)
P. AND salary > (SELECT salary
Q. FROM employees
R. WHERE first_name = 'Jessica'
S. AND last_name = 'Butcher'
T. AND employee_id = 40);
U. SELECT first_name, last_name
V. FROM employees
W. WHERE department = (SELECT department
X. FROM employees
Y. WHERE first_name = 'Jessica'
Z. AND last_name = 'Butcher'
AA. AND department = 100);

Answer: C. More than one sub-query can be written in one SQL statement
to add more than one condition.

20.Based on the answers for questions 18th and 19th, what type
of sub-queries is used by them?

A. Single row sub-query


B. Multiple row sub-query
C. Both A and B
D. Inline sub-query

Answer: A. The questions 18th and 19th given above demonstrate the
usage sub-queries in a SELECT statement.

21.Consider two statements about outer and inner queries in


context of SQL sub-queries?

i. The inner queries can get data from only one table

ii. The inner queries can get data from more than one table
Which of the above statements are true?

A. (i)
B. (ii)
C. Both (i) and (ii)
D. Neither (i) nor (ii)

Answer: B. Sub-queries can fetch data from more than one table.

Examine the table structure as follows and answer the questions


22 to 27 that follow:

SQL> DESC employees


Name Null? Type
----------------------- -------- ----------------
EMPLOYEE_ID NOT NULL NUMBER(6)
FIRST_NAME VARCHAR2(20)
LAST_NAME NOT NULL VARCHAR2(25)
EMAIL NOT NULL VARCHAR2(25)
PHONE_NUMBER VARCHAR2(20)
HIRE_DATE NOT NULL DATE
JOB_ID NOT NULL VARCHAR2(10)
SALARY NUMBER(8,2)
COMMISSION_PCT NUMBER(2,2)
MANAGER_ID NUMBER(6)
DEPARTMENT_ID NUMBER(4)

22.What will be the outcome of the following query? (Choose the


most appropriate answer)

SQL> DESC employees


Name Null? Type
----------------------- -------- ----------------
EMPLOYEE_ID NOT NULL NUMBER(6)
FIRST_NAME VARCHAR2(20)
LAST_NAME NOT NULL VARCHAR2(25)
EMAIL NOT NULL VARCHAR2(25)
PHONE_NUMBER VARCHAR2(20)
HIRE_DATE NOT NULL DATE
JOB_ID NOT NULL VARCHAR2(10)
SALARY NUMBER(8,2)
COMMISSION_PCT NUMBER(2,2)
MANAGER_ID NUMBER(6)
DEPARTMENT_ID NUMBER(4)
SELECT last_name, job_id, salary
FROM employees
WHERE salary = (SELECT max(salary)
FROM employees);

A. It executes successfully and gives the employees who have salaries equal to
the max salary.
B. It executes successfully but does not give the required results
C. It throws an error as a group function is used in the sub-query
D. It throws an error as a single row sub-query should contain a multi-row
operator

Answer: A. A group function can be used within a sub-query.

23.What will be the outcome of the query that follows?

SELECT first_name, last_name, min(salary)


FROM employees
GROUP BY department_id
HAVING MIN(salary) >
(SELECT min(salary)
FROM employees
WHERE department_id = 100);

A. It executes successfully and gives the names and minimum salary greater
than department 100 of all employees
B. It executes successfully and gives the salaries of the employees in
department 100
C. It executes successfully and gives the names and minimum salaries of all the
employees.
D. It throws an error.
Answer: A. HAVING clause can be used in sub-queries as shown

24.You need to find the job which has a maximum average


salary.Which of the following queries will give you the required
results?

A. SELECT job_id, avg(salary)


B. FROM employees
C. GROUP BY job_id;
D. SELECT job_id, avg(salary)
E. FROM employees
F. GROUP BY job_id
G. HAVING job_id in (SELECT max(avg(salary) FROM employees);
H. SELECT job_id, avg(salary)
I. FROM employees
J. GROUP BY job_id
K. HAVING max(avg(salary) in (SELECT max(avg(salary) FROM employees);
L. SELECT job_id, avg(salary)
M. FROM employees
N. GROUP BY job_id
O. HAVING avg(salary) in (SELECT max(avg(salary) FROM employees GROUP BY
job_id);

Answer: D. Sub-queries can make use of group functions and HAVING


clause to restrict the groups.

25.The following query throws an error. Choose the correct reason


for the error as given in the options.

SELECT first_name, last_name


FROM employees
WHERE commission_pct = (SELECT min(commission_pct )
FROM employees
GROUP BY department_id);

A. The GROUP BY clause is not required in the sub-query


B. A function cannot be used in a sub-query SELECT statement
C. The single row sub-query gives multiple records
D. The use of "=" operator is invalid; an IN operator will work correctly
Answer: C, D. The GROUP BY clause gives the minimum commission_pct
for each department and hence multiple results are fetched to the main
query giving an error.

26.Consider the query given below.How many records will be


returned as a result of the above query? (Assuming the no
employee with job id XX exists in the company)

SELECT first_name, last_name


FROM employees
WHERE salary = (SELECT salary
FROM employees
WHERE job_id = 'XX');

A. 1
B. NULL
C. 0
D. The query raises ORA error because sub-query is invalid.

Answer: C. Since there is no employee with job_id "XX" in the company,


the sub-query returns no result, which when equated to job_id in the main
query gives a 0.

27.What happens if the WHERE condition in the query given in


question 26 is replaced with a new one (WHERE job_id IS NOT
NULL)? (Assume the number of records in 'employees' table is 14).

A. 1
B. 14
C. 0
D. ORA error

Answer: D. The query execution raises the exception "ORA-01427:


single-row subquery returns more than one row".

28.Which of the following are valid multi row operators used for
sub-queries?

A. <=
B. ANY >=
C. !=
D. >=

Answer: B. Multiple-row subqueries return more than one row of


results.Operators that can be used with multiple-row subqueries include
IN, ALL, ANY, and EXISTS.The multi row operators IN, ANY, ALL must be
used with single row operators as shown in the option B.

Examine the table structure as given. Consider the query given


below and answer the questions 29 to 33 that follow

SQL> DESC employees


Name Null? Type
----------------------- -------- ----------------
EMPLOYEE_ID NOT NULL NUMBER(6)
FIRST_NAME VARCHAR2(20)
LAST_NAME NOT NULL VARCHAR2(25)
EMAIL NOT NULL VARCHAR2(25)
PHONE_NUMBER VARCHAR2(20)
HIRE_DATE NOT NULL DATE
JOB_ID NOT NULL VARCHAR2(10)
SALARY NUMBER(8,2)
COMMISSION_PCT NUMBER(2,2)
MANAGER_ID NUMBER(6)
DEPARTMENT_ID NUMBER(4)
SELECT first_name, last_name, salary, commission_pct
FROM employees
WHERE salary < ANY (SELECT salary
FROM employees
WHERE department_id = 100)
AND department_id <> 101;

29.What does the ANY operator evaluates to in the above query?

A. TRUE
B. FALSE
C. NULL
D. 0
Answer: A. The multi row operators return Boolean results. As there are
results of salary in the department 100, it returns TRUE. If there are 0
results, it evaluates to FALSE.

30.What will be the outcome of the query if we assume that the


department 100 has only one employee?

A. It executes successfully giving the one result


B. It executes successfully giving salaries of all the employees
C. NULL
D. It throws an ORA error

Answer: D. If the department 100 has one result (single row sub-query),
the < ANY operator gives the error as it is a multi-row operator.

31.What will be the outcome of the query given above if the < ANY
operator is replaced with = ANY operator?

A. Oracle will treat each value of the salary returned from the sub-query as it
does with IN operator
B. There will be no difference in the results
C. The results will differ
D. The execution will thrown an ORA error

Answer: A. = ANY operator is equivalent to IN operator.

32.What can be said about the < ANY operator in the query given
above?

A. It gives the maximum value of salary


B. It gives the minimum value of salary
C. It means it gives the values that are lesser than the highest
D. None of the above

Answer: C. The multi row operator < ANY evaluates to the statements
"Less than the maximum" of the subquery. '> ALL' More than the highest
value returned by the subquery. '< ALL' Less than the lowest value
returned by the subquery. '< ANY' Less than the highest value returned
by the subquery. '< ANY' More than the lowest value returned by the
subquery. '= ANY' Equal to any value returned by the subquery (same as
IN). '[NOT] EXISTS' Row must match a value in the subquery
<
33.Assume that the < ANY operator is replaced with the > ANY.
What is true about this operator?

A. It gives the maximum salary


B. It finds only the maximum salary from the sub-query
C. It gives more than the minimum salary
D. It gives the minimum salary

Answer: C. The multi row operator > ANY evaluates to the statements
"Greater than the minimum" of the subquery. '> ALL' More than the
highest value returned by the subquery. '< ALL' Less than the lowest value
returned by the subquery. '< ANY' Less than the highest value returned
by the subquery. '> ANY' More than the lowest value returned by the
subquery. '= ANY' Equal to any value returned by the subquery (same as
IN). '[NOT] EXISTS' Row must match a value in the subquery

<
34. Examine the given table structure and consider the following
query:

SQL> DESC employees


Name Null? Type
----------------------- -------- ----------------
EMPLOYEE_ID NOT NULL NUMBER(6)
FIRST_NAME VARCHAR2(20)
LAST_NAME NOT NULL VARCHAR2(25)
EMAIL NOT NULL VARCHAR2(25)
PHONE_NUMBER VARCHAR2(20)
HIRE_DATE NOT NULL DATE
JOB_ID NOT NULL VARCHAR2(10)
SALARY NUMBER(8,2)
COMMISSION_PCT NUMBER(2,2)
MANAGER_ID NUMBER(6)
DEPARTMENT_ID NUMBER(4)
SELECT employee_id, first_name, last_name
FROM employees
WHERE salary IN (SELECT max(salary)
FROM employees
GROUP BY department_id );

Which WHERE clause among the following is equivalent to that given in


the above query? (Assume that the salaries are 2500, 3000, 3500,4000)

A. WHERE salary < ANY (SELECT max(salary)


B. FROM employees
C. GROUP BY department_id );
D. WHERE salary < ALL (SELECT max(salary)
E. FROM employees
F. GROUP BY department_id );
G. WHERE salary = (SELECT max(salary)
H. FROM employees
I. GROUP BY department_id );
J. WHERE salary IN (2500,3000,3500,4000);

Answer: D. When the IN operator is used, Oracle treats individual results


of the sub-query as shown in the option D.

Examine the structure of the EMPLOYEES table as given below and


answer the questions 35 to 37 that follow.

SQL> DESC employees


Name Null? Type
----------------------- -------- ----------------
EMPLOYEE_ID NOT NULL NUMBER(6)
FIRST_NAME VARCHAR2(20)
LAST_NAME NOT NULL VARCHAR2(25)
EMAIL NOT NULL VARCHAR2(25)
PHONE_NUMBER VARCHAR2(20)
HIRE_DATE NOT NULL DATE
JOB_ID NOT NULL VARCHAR2(10)
SALARY NUMBER(8,2)
COMMISSION_PCT NUMBER(2,2)
MANAGER_ID NUMBER(6)
DEPARTMENT_ID NUMBER(4)

<
35. You need to find out which of the employees have a salary less
than that of the salary for the job ID 'FIN_ACT'. Which of the
following queries will give you the required output?

A. SELECT employee_id, first_name, last_name


B. FROM employees
C. WHERE salary < ALL
D. (SELECT salary
E. FROM employees
F. WHERE job_id = 'FIN_ACT')
G. AND job_id <> 'FIN_ACT';
H. SELECT employee_id, first_name, last_name
I. FROM employees
J. WHERE salary > ALL
K. (SELECT salary
L. FROM employees
M. WHERE job_id = 'FIN_ACT')
N. AND job_id <> 'FIN_ACT';
O. SELECT employee_id, first_name, last_name
P. FROM employees
Q. WHERE salary < ANY
R. (SELECT salary
S. FROM employees
T. WHERE job_id = 'FIN_ACT')
U. AND job_id <> 'FIN_ACT';
V. SELECT employee_id, first_name, last_name
W. FROM employees
X. WHERE salary = (SELECT salary
Y. FROM employees
Z. WHERE job_id = 'FIN_ACT')
AA. AND job_id <> 'FIN_ACT';

Answer: A. < ALL means less than the minimum. '> ALL' More than the
highest value returned by the subquery. '< ALL' Less than the lowest value
returned by the subquery. '< ANY' Less than the highest value returned
by the subquery. '> ANY' More than the lowest value returned by the
subquery. '= ANY' Equal to any value returned by the subquery (same as
IN). '[NOT] EXISTS' Row must match a value in the subquery

36.What will be the outcome of the above query (the option A in


the question above), if the < ALL is replaced with the >ALL?

A. It will execute successfully giving the same result.


B. It will throw an ORA error
C. It will execute successfully but give the employees' details who have salaries
lesser than all the employees with job_id 'FI_ACCOUNTANT'.
D. None of the above

Answer: C. >ALL means less than the minimum. '> ALL' More than the
highest value returned by the subquery. '< ALL' Less than the lowest value
returned by the subquery. '< ANY' Less than the highest value returned
by the subquery. '> ANY' More than the lowest value returned by the
subquery. '= ANY' Equal to any value returned by the subquery (same as
IN). '[NOT] EXISTS' Row must match a value in the subquery

37.You need to find the salaries for all employees who are not in
the department 100. Which of the following queries will give you
the required result?

A. SELECT employee_id, first_name, last_name


B. FROM employees
C. WHERE salary !=ALL
D. (SELECT salary
E. FROM employees
F. WHERE department_id = 100)
G. AND department_id <> 100;
H. SELECT employee_id, first_name, last_name
I. FROM employees
J. WHERE salary NOT IN
K. (SELECT salary
L. FROM employees
M. WHERE department_id = 100)
N. AND department_id <> 100;
O. SELECT employee_id, first_name, last_name
P. FROM employees
Q. WHERE salary NOT ALL
R. (SELECT salary
S. FROM employees
T. WHERE department_id = 100)
U. AND department_id <> 100;
V. SELECT employee_id, first_name, last_name
W. FROM employees
X. WHERE salary != (SELECT salary
Y. FROM employees
Z. WHERE department_id = 100)
AA. AND department_id <> 100;

Answer: C. NOT can be used with the multi row operators IN, ANY and
ALL.

Examine the table structure as given. Consider the following query and
answer the questions 38 and 39 that follow. You need to find the
employees who do not have a sub-ordinate reporting to them. (Assume
there are 0 expected results)

SQL> DESC employees


Name Null? Type
----------------------- -------- ----------------
EMPLOYEE_ID NOT NULL NUMBER(6)
FIRST_NAME VARCHAR2(20)
LAST_NAME NOT NULL VARCHAR2(25)
EMAIL NOT NULL VARCHAR2(25)
PHONE_NUMBER VARCHAR2(20)
HIRE_DATE NOT NULL DATE
JOB_ID NOT NULL VARCHAR2(10)
SALARY NUMBER(8,2)
COMMISSION_PCT NUMBER(2,2)
MANAGER_ID NUMBER(6)
DEPARTMENT_ID NUMBER(4)
SELECT first_name, last_name
FROM employees
WHERE employee_id NOT IN
(SELECT manager_id
FROM employees);

38.What will be the result of the query given above?

A. 10
B. NULL
C. ORA error
D. 0

Answer: D. One of the values in the inner sub-query is NULL (all


employees are not managers!)

39.Which of the following WHERE clauses should be added /


modified to the above query to give the expected results?

A. WHERE employee_id != (SELECT manager_id FROM employees);


B. WHERE employee_id IN (SELECT manager_id FROM employees);
C. WHERE employee_id <>ALL (SELECT manager_id FROM employees);
D. WHERE employee_id NOT IN (SELECT manager_id
E. FROM employees
F. WHERE manager_id is NOT NULL);

Answer: B, D. If the sub-query is likely to have NULL values, do not use


the NOT IN operator or if using, modify the sub-query with an additional
WHERE clause (option D)

40.What is true about sub-queries in general?

A. Sub-queries have to be executed separately from the main queries


B. Sub-queries can be executed at the will of the user, they are not related to
the main query execution
C. Sub-queries are equal to two sequential queries where the results of inner
query are used by the main query
D. All of the above

Answer: C.

41. Which of the following is true about sub-queries?

A. A sub-query can return 0 or more rows


B. A sub-query can be used only in the SELECT clause
C. Nesting of sub-queries is limited to 2 levels
D. Group functions cannot be used in sub-queries

Answer: A. A subquery is a complete query nested in the SELECT, FROM,


HAVING, or WHERE clause of another query. The subquery must be
enclosed in parentheses and have a SELECT and a FROM clause, at a
minimum. A single-row subquery can return a maximum of one value.
Multiple-column subqueries return more than one column to the outer
query.

42. Examine the table structure as given.

SQL> DESC employees


Name Null? Type
----------------------- -------- ----------------
EMPLOYEE_ID NOT NULL NUMBER(6)
FIRST_NAME VARCHAR2(20)
LAST_NAME NOT NULL VARCHAR2(25)
EMAIL NOT NULL VARCHAR2(25)
PHONE_NUMBER VARCHAR2(20)
HIRE_DATE NOT NULL DATE
JOB_ID NOT NULL VARCHAR2(10)
SALARY NUMBER(8,2)
COMMISSION_PCT NUMBER(2,2)
MANAGER_ID NUMBER(6)
DEPARTMENT_ID NUMBER(4)

Consider the following query.

SELECT first_name, last_name


FROM employees
WHERE employee_id NOT IN
(SELECT manager_id, hire_date
FROM employees
WHERE manager_id is not null);

This query returns an error. What is the reason for error?


A. The NOT IN operator used is invalid
B. The WHERE clause in the sub-query is incorrectly written
C. The column in the sub-query SELECT clause should only be one when there's
an inequality used in the main query
D. The sub-query uses the same table as the main query

Answer: C. The columns selected in the sub-query should be same as on


the other side of comparison operator. Any inequality of data type or
number of columns would result in an ORA error.

43.A report has to be extracted which displays all the departments


that have one or more employees assigned to them. Which of the
following queries will give the required output? (Consider the table
structure as given)

SQL> DESC employees


Name Null? Type
----------------------- -------- ----------------
EMPLOYEE_ID NOT NULL NUMBER(6)
FIRST_NAME VARCHAR2(20)
LAST_NAME NOT NULL VARCHAR2(25)
EMAIL NOT NULL VARCHAR2(25)
PHONE_NUMBER VARCHAR2(20)
HIRE_DATE NOT NULL DATE
JOB_ID NOT NULL VARCHAR2(10)
SALARY NUMBER(8,2)
COMMISSION_PCT NUMBER(2,2)
MANAGER_ID NUMBER(6)
DEPARTMENT_ID NUMBER(4)

A. SELECT department_name
B. FROM employees
C. WHERE department_id IN (SELECT distinct (department_id )
D. FROM employees);
E. SELECT department_name
F. FROM employees
G. WHERE department_id ANY (SELECT distinct (department_id )
H. FROM employees);
I. SELECT department_name
J. FROM employees
K. WHERE department_id < ANY (SELECT distinct (department_id )
L. FROM employees);
M. SELECT department_name
N. FROM employees
O. WHERE department_id = ANY (SELECT distinct (department_id )
P. FROM employees);

Answer: A, D.

44.What is the maximum level of sub-queries allowed in Oracle in


a single SQL statement?

A. 20
B. 50
C. Unlimited
D. 255

Answer: D. Oracle supports the Nesting of queries to 255 levels.

45. What should be the best practice to follow when we know what
values we need to pass on to the main query in Oracle queries?

A. Using GROUP BY
B. Using sub-queries
C. Using HAVING
D. None of the above

Answer: D. It might become possible that the sub-queries give a NULL


result, which results in 0 rows in the main result; hence it is a good practice
to use them only if we know what values we need.

Examine the table structure as given. Consider the following query


and answer the questions 46 and 47 that follow:

SQL> DESC employees


Name Null? Type
----------------------- -------- ----------------
EMPLOYEE_ID NOT NULL NUMBER(6)
FIRST_NAME VARCHAR2(20)
LAST_NAME NOT NULL VARCHAR2(25)
EMAIL NOT NULL VARCHAR2(25)
PHONE_NUMBER VARCHAR2(20)
HIRE_DATE NOT NULL DATE
JOB_ID NOT NULL VARCHAR2(10)
SALARY NUMBER(8,2)
COMMISSION_PCT NUMBER(2,2)
MANAGER_ID NUMBER(6)
DEPARTMENT_ID NUMBER(4)
SELECT employee_id, first_name, last_name, job_id
FROM employees
WHERE job_id = (SELECT job_id FROM employees);

46.You need to find all the employees whose job ID is the same as
that of an employee with ID as 210. Which of the following WHERE
clauses would you add / modify to achieve this result? (Consider
the table structure as given

A. WHERE job_id = (SELECT job_id FROM employees WHERE employee_id = 210);


B. WHERE job_id IN (SELECT job_id FROM employees WHERE employee_id = 210);
C. WHERE job_id > (SELECT job_id FROM employees WHERE employee_id = 210);
D. WHERE job_id >= (SELECT job_id FROM employees WHERE employee_id = 210);

Answer: A.

47.Assume that you change the WHERE clause as given in the


option A in question 46 as the following.

WHERE job_id = (SELECT job_id FROM employees WHERE employee_id < 210);

What will be the outcome of this change?

A. The results will be the same


B. ORA error thrown on execution
C. The results will differ
D. The query will execute successfully giving 0 rows.
Answer: B. The sub-query gives more than one result on the given
change and hence a multi row operator should replace the "=" in the main
query given above.

48.Examine the table structures as shown in the exhibit below.

You need to display the names of the employees who have the highest
salary. Which of the following SQL statements will be correct?

A. SELECT first_name, last_name, grade


B. FROM employees, grade
C. WHERE (SELECT max (salary) FROM employees) BETWEEN losal and hisal;
D. SELECT first_name, last_name, grade
E. FROM employees, grade
F. WHERE (SELECT max (salary) FROM employees) BETWEEN losal and hisal
G. AND salary BETWEEN losal and hisal;
H. SELECT first_name, last_name, grade
I. FROM employees, grade
J. WHERE salary = (SELECT max (salary) FROM employees)
K. AND salary BETWEEN losal and hisal;
L. SELECT first_name, last_name, grade
M. FROM employees, grade
N. WHERE salary IN (SELECT max (salary) FROM employees)
O. AND max(salary) BETWEEN losal and hisal;

Answer: B, C. The sub-queries can be written on either side of the


operator

49.What is the sub-query in the FROM clause of an SQL statement?


(Choose the most appropriate answer)
A. Single row sub-query
B. Multi row sub-query
C. Inline View
D. Co-related sub-query

Answer: C. If a sub-query appears in the FROM clause of the SELECT


statements,it forms an Inline view. Oracle internally creates a temporary
view for the query execution.

50.What is the maximum number of nesting level allowed in an


Inline View type sub-query?

A. 255
B. 300
C. 216
D. Unlimited

Answer: D. As there is no limit on the number of tables which can be


joined, there is no limit on the number of inline view in a query.

51.What is true about co-related sub-queries?

A. The tables used in the main query are also used in a co-related sub-query
B. The sub-queries which reference a column used in the main query are called
co-related sub-queries
C. The sub-queries which are written without parenthesis are called co-related
sub-queries
D. The sub-queries which mandatorily use different tables than those used in the
main query are called co-related sub-queries

Answer: B. Correlated subquery references a column in the outer query


and executes the subquery once for every row in the outer query while
Uncorrelated subquery executes the subquery first and passes the value
to the outer query.

52.Which of the following statements cannot be parent statements


for a sub-query?

A. SELECT
B. GROUP BY
C. UPDATE
D. DELETE

Answer: B. The rest of the options can be in the main query (parent
query) of a sub-query.

53.What is true about a co-related sub-query?

A. It is evaluated only once for the parent query


B. It is evaluated only thrice for the parent query
C. It is evaluated once for each row processed by the parent sub-query
D. All of the above

Answer: C. Correlated subquery references a column in the outer query


and executes the subquery once for every row in the outer query;and the
EXISTS operator is used to test whether the relationship or link is present.

54.Examine the given table structure. You need to write a query


which returns the names of the employees whose salaries exceed
their respective department's average salary. Which of the
following will work? (Choose the most appropriate answer)

SQL> DESC employees


Name Null? Type
----------------------- -------- ----------------
EMPLOYEE_ID NOT NULL NUMBER(6)
FIRST_NAME VARCHAR2(20)
LAST_NAME NOT NULL VARCHAR2(25)
EMAIL NOT NULL VARCHAR2(25)
PHONE_NUMBER VARCHAR2(20)
HIRE_DATE NOT NULL DATE
JOB_ID NOT NULL VARCHAR2(10)
SALARY NUMBER(8,2)
COMMISSION_PCT NUMBER(2,2)
MANAGER_ID NUMBER(6)
DEPARTMENT_ID NUMBER(4)

A. SELECT employee_id, first_name, last_name


B. FROM employees e
C. WHERE salary > (SELECT avg (salary)
D. FROM employees
E. WHERE e.department_id = department_id )
F. ORDER BY department_id ;
G. SELECT employee_id, first_name, last_name
H. FROM employees e
I. WHERE salary > ANY (SELECT avg(salary)
J. FROM employees
K. WHERE e.department_id = department_id )
L. ORDER BY department_id ;
M. SELECT employee_id, first_name, last_name
N. FROM employees e
O. WHERE salary = (SELECT avg(salary)
P. FROM employees
Q. WHERE e.department_id = department_id )
R. ORDER BY department_id ;
S. SELECT employee_id, first_name, last_name
T. FROM employees e
U. WHERE salary < ANY (SELECT avg(salary)
V. FROM employees
W. WHERE e.department_id = department_id )
X. ORDER BY department_id ;

Answer: A. Here the department ID is obtained, used to evaluate the


parent query and if the salary in that row is greater than the average salary
of the departments of that row, that result is returned.

55.Examine the given table structure. Which of the following


queries will display duplicate records in a table EMPLOYEES?

SQL> DESC employees


Name Null? Type
----------------------- -------- ----------------
EMPLOYEE_ID NOT NULL NUMBER(6)
FIRST_NAME VARCHAR2(20)
LAST_NAME NOT NULL VARCHAR2(25)
EMAIL NOT NULL VARCHAR2(25)
PHONE_NUMBER VARCHAR2(20)
HIRE_DATE NOT NULL DATE
JOB_ID NOT NULL VARCHAR2(10)
SALARY NUMBER(8,2)
COMMISSION_PCT NUMBER(2,2)
MANAGER_ID NUMBER(6)
DEPARTMENT_ID NUMBER(4)

A. SELECT *
B. FROM employees E
C. WHERE exists (SELECT 1 FROM employees E1
D. WHERE E.employee_id = E1.employee_id);
E. SELECT *
F. FROM employees E
G. WHERE exists (SELECT 1 FROM employees E1
H. WHERE E.employee_id = E1.employee_id
I. AND E.ROWID < E1.ROWID);
J. SELECT *
K. FROM employees E
L. WHERE exists (SELECT 1 FROM employees E1
M. WHERE E.ROWID < E1.ROWID);
N. SELECT *
O. FROM employees E
P. WHERE = ANY (SELECT 1 FROM employees E1
Q. WHERE E.employee_id = E1.employee_id
R. And E.ROWID < E1.ROWID);

Answer: A. Correlated subquery references a column in the outer query


and executes the subquery once for every row in the outer query;and the
EXISTS operator is used to test whether the relationship or link is present.
It can be used to find the duplicate rows in a table where duplicity is
subjected to a column or set of columns.

Examine the structures for the tables DEPARTMENTS and


EMPLOYEES and answer the questions 56 and 57 that follow.

SQL> DESC employees


Name Null? Type
----------------------- -------- ----------------
EMPLOYEE_ID NOT NULL NUMBER(6)
FIRST_NAME VARCHAR2(20)
LAST_NAME NOT NULL VARCHAR2(25)
EMAIL NOT NULL VARCHAR2(25)
PHONE_NUMBER VARCHAR2(20)
HIRE_DATE NOT NULL DATE
JOB_ID NOT NULL VARCHAR2(10)
SALARY NUMBER(8,2)
COMMISSION_PCT NUMBER(2,2)
MANAGER_ID NUMBER(6)
DEPARTMENT_ID NUMBER(4)
SQL> DESC departments
Name Null? Type
----------------------- -------- ----------------
DEPARTMENT_ID NOT NULL NUMBER(4)
DEPARTMENT_NAME NOT NULL VARCHAR2(30)
MANAGER_ID NUMBER(6)
LOCATION_ID NUMBER(4)

56.Which of the following queries will display the system date and
count of records in the DEPARTMENTS and EMPLOYEES table?

A. SELECT sysdate,
B. (SELECT * FROM departments) dept_count,
C. (SELECT * FROM employees) emp_count
D. FROM DUAL;
E. SELECT sysdate,
F. (SELECT count(*) FROM departments) dept_count,
G. (SELECT count(*) FROM employees) emp_count
H. FROM DUAL
I. GROUP BY department_id ;
J. SELECT sysdate,
K. (SELECT * FROM departments) dept_count,
L. (SELECT * FROM employees) emp_count
M. FROM DUAL
N. GROUP BY employee_id;
O. SELECT sysdate,
P. (SELECT count(*) FROM departments) dept_count,
Q. (SELECT count(*) FROM employees) emp_count
R. FROM DUAL;

Answer: D. A single-row subquery can also be nested in the outer query's


SELECT clause. In this case, the value the subquery returns is available
for every row of output the outer query generates. Typically, this technique
is used to perform calculations with a value produced from a subquery.

57.Which of the following queries will tell whether a given


employee is a manager in a Company 'XYZ'?

A. SELECT employee_id, manager_id


B. FROM employees A
C. WHERE employee_id ANY (SELECT manager_id from employees B)
D. ORDER BY manager_id desc;
E. SELECT employee_id, manager_id
F. FROM employees A
G. WHERE employee_id < ALL (SELECT manager_id from employees B)
H. SELECT employee_id, manager_id
I. FROM employees A
J. WHERE employee_id IN (SELECT manager_id from employees B)
K. ORDER BY manager_id desc;
L. SELECT employee_id, manager_id
M. FROM employees A
N. WHERE employee_id in (SELECT manager_id from employees B)
O. GROUP BY department_id ;

Answer: C.

Examine the exhibit and answer the question 58 that follows:


58.Which of the following queries will give you maximum salary of
an employee in a particular city?

A. SELECT max (salary), city


B. FROM
C. (SELECT salary, department_id , loc, city
D. FROM employees natural join departments natural join locations);
E. SELECT salary, city
F. FROM
G. (SELECT salary, department_id , loc, city
H. FROM employees natural join departments natural join locations);
I. SELECT max (salary), city
J. FROM
K. (SELECT salary, department_id , loc, city
L. FROM employees natural join departments natural join locations)
M. GROUP BY city;
N. SELECT max (avg(salary)), city
O. FROM
P. (SELECT salary, department_id , loc, city
Q. FROM employees natural join departments natural join locations);

Answer: C. When a multiple-column subquery is used in the outer query's


FROM clause, it creates a temporary table that can be referenced by other
clauses of the outer query. This temporary table is more formally called an
inline view. The subquery's results are treated like any other table in the
FROM clause. If the temporary table contains grouped data, the grouped
subsets are treated as separate rows of data in a table.

Examine the table structures as given below.

SQL> DESC employees


Name Null? Type
----------------------- -------- ----------------
EMPLOYEE_ID NOT NULL NUMBER(6)
FIRST_NAME VARCHAR2(20)
LAST_NAME NOT NULL VARCHAR2(25)
EMAIL NOT NULL VARCHAR2(25)
PHONE_NUMBER VARCHAR2(20)
HIRE_DATE NOT NULL DATE
JOB_ID NOT NULL VARCHAR2(10)
SALARY NUMBER(8,2)
COMMISSION_PCT NUMBER(2,2)
MANAGER_ID NUMBER(6)
DEPARTMENT_ID NUMBER(4)
SQL> DESC departments
Name Null? Type
----------------------- -------- ----------------
DEPARTMENT_ID NOT NULL NUMBER(4)
DEPARTMENT_NAME NOT NULL VARCHAR2(30)
MANAGER_ID NUMBER(6)
LOCATION_ID NUMBER(4)

Consider the following query and answer the questions that 59 to 62 that
follow.

SELECT department_name
FROM departments d INNER JOIN employees e
ON (d.employee_id = e.employee_id)
GROUP BY department_name;

59.Which of the following queries can replace the above query by


using sub-queries giving the same result?

A. SELECT department_name
B. FROM departments
C. WHERE department_id = ANY (SELECT department_id FROM employees);
D. SELECT department_name
E. FROM departments
F. WHERE department_id IN (SELECT distinct(department_id ) FROM employees);
G. SELECT department_name
H. FROM departments
I. WHERE department_id = (SELECT distinct(department_id ) FROM employees);
J. SELECT department_name
K. FROM departments
L. WHERE department_id ANY (SELECT distinct(department_id ) FROM employees);

Answer: A, B.

60.Assume that the sub-query as shown in the query given above


is modified to the following.

(SELECT distinct (department_id ) FROM employees ORDER BY department_id );

What will be the outcome as a result of this change? (Choose the most
appropriate answer)

A. It will order the department_id fetched from the sub-query and display them
in ascending order
B. It will throw an ORA error as the ORDER BY clause should be accompanied by
the GROUP BY clause
C. It will throw an ORA error because an ORDER BY clause cannot be used inside
a sub-query
D. It will execute successfully.

Answer: C. A subquery, except one in the FROM clause, can't have an


ORDER BY clause.If you need to display output in a specific order, include
an ORDER BY clause as the outer query's last clause.

61.Assume that the query given above is modified as the below


one.

SELECT department_name
FROM departments
WHERE department_id = ANY (SELECT department_id FROM employees)
ORDER BY department_id desc;

What will be the outcome as a result of this change? (Choose the most
appropriate answer)

A. It will order the department_id fetched from the sub-query and display them
in ascending order
B. It will order the department_id fetched from the sub-query and display them
in descending order
C. It will throw an ORA error because an ORDER BY clause cannot be used inside
a sub-query
D. None of the above

Answer: D. A subquery, except one in the FROM clause, can't have an


ORDER BY clause.If you need to display output in a specific order, include
an ORDER BY clause as the outer query's last clause.

62.Which of the following can be used to order results in a sub-


query?

A. ORDER BY
B. HAVING
C. GROUP BY
D. All of the above

Answer: C. By default, the GROUP BY clause performs ordering in a sub-


query.

Examine the exhibit below and answer the questions 63 to 65 that


follow:

Consider the following query:

SELECT au_id, au_title


FROM audit
WHERE au_details in (SELECT au_details
FROM audit
WHERE au_title like 'S%')
ORDER BY au_title;

63.What will be the outcome of the query given above?

A. It gives all AU_ID and AU_TITLEs starting with the letter 'S%'
B. It gives all AU_ID and AU_TITLEs starting with the letter 'S%' ordered by the
titles in ascending order
C. It throws an ORA error
D. It returns a 0 value

Answer: C. A column with a CLOB, BLOB, NCLOB or an ARRAY cannot be


used in a sub-query.

64. What will be the outcome of the following query?

SELECT *
FROM employees
WHERE salary BETWEEN (SELECT max(salary)
FROM employees
WHERE department_id = 100)
AND (SELECT min(salary) FROM employees where department_id = 100);

This query returns an error. What is the reason for the error?

A. A GROUP BY clause should be used as the function MAX is used


B. Both the sub-queries cannot use the same department ID in the same outer
query
C. BETWEEN operator cannot be used with a sub-query
D. SELECT clause should have columns mentioned and not a asterix (*)

Answer: C. The BETWEEN operator can be used within a sub-query but


not with a sub-query.

65.What is true about using NOT IN when writing queries with sub-
queries in them?

A. NOT IN ignores all the NULL values and gives only the NOT NULL values
B. NOT IN puts all the NULL values at the last and gives the NOT NULL to be
displayed first
C. NOT IN should be not be used if a NULL value is expected in the result set
D. NOT IN is just a negation of the operator IN and can be changed without any
caveat.

Answer: C. SQL handles NULL values in a different way and hence it is a


good practice to avoid NOT IN if the result set might contain a NULL.

Consider the following table structures and answer the questions


66 to 72 that follow:

66. You need to find out the names and IDs of the departments in
which the least salary is greater than the highest salary in the
department 10. Which of the following queries will give the
required result.

A. SELECT department_id , min(salary)


B. FROM employees
C. GROUP BY department_id
D. HAVING min(salary) >
E. (
F. select max(salary)
G. FROM employees
H. where department_id = 10
I. )
J. SELECT department_id , min(salary)
K. FROM employees
L. GROUP BY department_id
M. HAVING min(salary) > ANY
N. (
O. select max(salary)
P. FROM employees
Q. )
R. SELECT department_id , min(salary)
S. FROM employees
T. HAVING max(salary) < ANY
U. (
V. select min(salary)
W. FROM employees
X. where department_id = 10
Y. )
Z. SELECT department_id , min(salary)
AA. FROM employees
BB. GROUP BY department_id
CC. HAVING min(salary) > ALL
DD. (
EE. select max(salary)
FF. FROM employees
GG. where department_id = 10
HH. )

Answer: A.

67.Write a query to find the employees whose salary is equal to


the salary of at least one employee in department of id 10. (Choose
the best answer)

A. SELECT employee_id, Salary


B. FROM employees
C. WHERE salary in
D. (
E. SELECT salary
F. FROM employees
G. where department_id = 10
H. )
I. SELECT employee_id, Salary
J. FROM employees
K. WHERE salary =ANY
L. (
M. SELECT salary
N. FROM employees
O. where department_id = 10
P. )
Q. SELECT employee_id, Salary
R. FROM employees
S. WHERE salary ALL
T. (
U. SELECT salary
V. FROM employees
W. where department_id = 10
X. )
Y. SELECT employee_id, Salary
Z. FROM employees
AA. WHERE salary < ANY
BB. (
CC. SELECT salary
DD. FROM employees
EE. where department_id = 10
FF. )

Answer: A, B.

68.You need to find out all the employees who have salary greater
than at least one employee in the department 10. Which of the
following queries will give you the required output?

A. SELECT employee_id, Salary


B. FROM employees
C. WHERE salary >= ANY
D. (
E. SELECT salary
F. FROM employees
G. where department_id = 10
H. )
I. SELECT employee_id, Salary
J. FROM employees
K. WHERE salary > ANY
L. (
M. SELECT salary
N. FROM employees
O. where department_id = 10
P. )
Q. SELECT employee_id, Salary
R. FROM employees
S. WHERE salary < ANY
T. (
U. SELECT salary
V. FROM employees
W. where department_id = 10
X. )
Y. SELECT employee_id, Salary
Z. FROM employees
AA. WHERE salary = ALL
BB. (
CC. SELECT salary
DD. FROM employees
EE. where department_id = 10
FF. )

Answer: B.

69.You need to find out all the employees who have salary lesser
than the salary of all the employees in the department 10. Which
of the following queries will give you the required output?

A. SELECT employee_id, Salary


B. FROM employees
C. WHERE salary > ALL
D. (
E. SELECT salary
F. FROM employees
G. where department_id = 10
H. )
I. SELECT employee_id, Salary
J. FROM employees
K. WHERE salary =ALL
L. (
M. SELECT salary
N. FROM employees
O. where department_id = 10
P. )
Q. SELECT employee_id, Salary
R. FROM employees
S. WHERE salary < ALL
T. (
U. SELECT salary
V. FROM employees
W. where department_id = 10
X. )
Y. SELECT employee_id, Salary
Z. FROM employees
AA. WHERE salary < ANY
BB. (
CC. SELECT salary
DD. FROM employees
EE. where department_id = 10
FF. )

Answer: C. Multiple-row subqueries return more than one row of results.


Operators that can be used with multiple-row subqueries include IN, ALL,
ANY, and EXISTS.Multiple-column subqueries return more than one
column to the outer query. The columns of data are passed to the outer
query in the same order in which they're listed in the subquery's SELECT
clause.
70.You need to find out all the employees who have their manager
and department matching with the employee having an Employee
ID of 121 or 200. Which of the following queries will give you the
required output?

A. SELECT employee_id, manager_id,department_id


B. FROM employees
C. WHERE (manager_id,department_id ) = ANY
D. (
E. select manager_id,
F. department_id
G. FROM employees
H. where employee_id in (121,200)
I. )
J. SELECT employee_id, manager_id,department_id
K. FROM employees
L. WHERE (manager_id,department_id ) < ANY
M. (
N. select manager_id,
O. department_id
P. FROM employees
Q. where employee_id in (121,200)
R. )
S. SELECT employee_id, manager_id,department_id
T. FROM employees
U. WHERE (manager_id,department_id ) > ANY
V. (
W. select manager_id,
X. department_id
Y. FROM employees
Z. where employee_id in (121,200)
AA. )
BB. SELECT employee_id, manager_id,department_id
CC. FROM employees
DD. WHERE (manager_id,department_id ) in
EE. (
FF. select manager_id,
GG. department_id
HH. FROM employees
II. where employee_id in (121,200)
JJ. )

Answer: A, D. Multiple-row subqueries return more than one row of


results. Operators that can be used with multiple-row subqueries include
IN, ALL, ANY, and EXISTS. Multiple-column subqueries return more than
one column to the outer query. The columns of data are passed to the
outer query in the same order in which they're listed in the subquery's
SELECT clause.

71.You need to find the department name of an employee with


employee ID 200. Which of the following queries will be correct?
(Choose the most appropriate answer)

A. SELECT employee_id, first_name, last_name,department_id ,


B. (SELECT department_name
C. FROM departments d, employees E
D. WHERE d.department_id = e.department_id
E. And employee_id = 200
F. )
G. FROM employees e
H. SELECT employee_id, first_name, last_name,department_id ,
I. (SELECT department_ID
J. FROM departments d
K. WHERE d.department_id = department_id
L. )
M. FROM employees e
N. WHERE employee_id = 200;
O. SELECT employee_id, first_name, last_name,department_id ,
P. (SELECT department_name
Q. FROM departments d
R. WHERE d.department_id = e.department_id
S. And employee_id = 200
T. )
U. FROM employees e
V. SELECT employee_id, first_name, last_name,department_id ,
W. (SELECT department_name
X. FROM departments d,employee E
Y. WHERE d.department_id = e.department_id
Z. )
AA. FROM employees e

Answer: C.

72.You need to find the highest earning employee with the job ID
as 'SA_REP'. Which of the following queries will be correct?
(Choose the most appropriate answer)

A. SELECT job_id, employee_id, Salary


B. FROM employees e
C. WHERE job_id =
D. (
E. SELECT distinct salary
F. FROM employees E1
G. WHERE E.job_id = E1.job_id
H. AND E.salary <= E1.salary
I. AND job_id = 'SA_REP'
J. SELECT department_id , employee_id, Salary
K. FROM employees E
L. WHERE 1 =
M. (
N. SELECT count(distinct salary)
O. FROM employees E1
P. WHERE E.job_id = E1.job_id
Q. AND E.salary <= E1.salary
R. AND job_id = 'SA_REP'
S. )
T. SELECT department_id , employee_id, Salary
U. FROM employees E
V. WHERE 0 =
W. (
X. SELECT count(distinct salary)
Y. FROM employees E1
Z. WHERE E.job_id = E1.job_id
AA. AND E.salary = E1.salary
BB. AND job_id = 'SA_REP'
CC. )
DD. SELECT department_id , employee_id, Salary
EE. FROM employees E
FF. WHERE 1 =
GG. (
HH. SELECT salary
II. FROM employees E1
JJ. WHERE E.job_id < E1.job_id
KK. AND E.salary <= E1.salary
LL. AND job_id = 'SA_REP'
MM. )

Answer: B.

Consider the EMPLOYEES table structure as shown in the exhibit


and answer the questions 73 to 77 that follow:

73.You need to find the job which has at least one employee in it.
Which of the following queries will be correct? (Choose the most
appropriate answer)

A. SELECT employee_id, Job_id


B. FROM employees E
C. WHERE exists
D. (
E. SELECT 1
F. FROM employees E1
G. WHERE E.job_id = E1.job_id )
H. SELECT employee_id, Job_id
I. FROM employees E
J. WHERE exists
K. (
L. SELECT *
M. FROM employees E1
N. WHERE E.job_id = E1.job_id )
O. SELECT employee_id, Job_id
P. FROM employees E
Q. WHERE not exists
R. (
S. SELECT *
T. FROM employees E1
U. WHERE E.job_id = E1.job_id )
V. SELECT employee_id, Job_id
W. FROM employees E
X. WHERE exists
Y. (
Z. SELECT 1
AA. FROM employees E1
BB. WHERE E.job_id < E1.job_id )

Answer: A. The EXISTS operator is used to check and match records


between queries. It returns a BOOLEAN value. Correlated subquery
references a column in the outer query and executes the subquery once
for every row in the outer query;and the EXISTS operator is used to test
whether the relationship or link is present. An Uncorrelated subquery
executes the subquery first and passes the value to the outer query.

74.You need to find the job which has no employees in it. Which of
the following queries will be correct? (Choose the most
appropriate answer)
A. SELECT employee_id, Job_id
B. FROM employees E
C. WHERE exists
D. (
E. SELECT *
F. FROM employees E1
G. WHERE E.job_id = E1.job_id )
H. SELECT employee_id, Job_id
I. FROM employees E
J. WHERE not exists
K. (
L. SELECT 1
M. FROM employees E1
N. WHERE E.job_id = E1.job_id )
O. SELECT employee_id, Job_id
P. FROM employees E
Q. WHERE not exists
R. (
S. SELECT *
T. FROM employees E1
U. WHERE E.job_id = E1.job_id )
V. SELECT employee_id, Job_id
W. FROM employees E
X. WHERE exists
Y. (
Z. SELECT 1
AA. FROM employees E1
BB. WHERE E.job_id < E1.job_id )

Answer: B. The NOT EXISTS is the negation operator for EXISTS.

75.You need to find the 3rd maximum salary from the EMPLOYEES
table. Which of the following queries will give you the required
results? (Choose the most appropriate answer)

A. SELECT *
B. FROM employees E
C. WHERE salary = (SELECT count(distinct salary )
D. FROM employees
E. WHERE e.salary = salary
F. );
G. SELECT *
H. FROM employees E
I. WHERE 1 = (SELECT count(distinct salary )
J. FROM employees
K. WHERE e.salary < salary
L. );
M. SELECT *
N. FROM employees E
O. WHERE 2 = (SELECT count(distinct salary )
P. FROM employees
Q. WHERE e.salary >salary
R. );
S. SELECT *
T. FROM employees E
U. WHERE 3 = (SELECT count(distinct salary )
V. FROM employees
W. WHERE e.salary <= salary
X. );

Answer: D.

76. You need to find the maximum salary by using the user input
for getting the value of N. Which of the following queries will give
you the required results? (Choose the most appropriate answer)

A. SELECT salary FROM


B. (
C. SELECT rowid as user_sal
D. FROM (SELECT distinct salary from employees ORDER BY salary desc)
E. )
F. WHERE user_sal=&N ;
G. SELECT salary FROM
H. (
I. SELECT rownum as user_sal
J. FROM (SELECT distinct salary FROM employees GROUP BY salary
)
K. )
L. WHERE user_sal <= &N ;
M. SELECT salary FROM
N. (
O. SELECT rownum as user_sal, salary FROM (SELECT distinct salary
FROM employees ORDER BY salary desc)
P. )
Q. WHERE user_sal=&N ;
R. SELECT salary FROM
S. (
T. SELECT max(rownum) as user_sal, salary FROM (SELECT distinct salary
FROM employees ORDER BY salary desc)
U. )
V. WHERE user_sal=&N ;

Answer: C. ROWNUM is a pseudo column used for finding the nth order
results.

77.What will happen if a value is provided to the &N variable in the


above query (option C in question 76) does not match with any
row? (Choose the best answer)

A. The statement would throw an ORA error


B. The statement would return all the rows in the table
C. The statement would return NULL as the output result.
D. The statement would return no rows in the result.

Answer: D.

78.What is the maximum level up to which Sub-queries can be


nested?

A. 255
B. 100
C. 2
D. 16
Answer: A.

79.What is true about the EXISTS operator in SQL queries with


respect to sub-queries?

A. The columns selected in the sub-queries are important


B. The inner query's should return rows, any result is what is important, not
what is SELECTED
C. Both A and B
D. Neither A nor B

Answer: B.

80.What is true about the ANY operator used for sub-queries?

A. Returns rows that match all the values in a list/sub-query


B. Returns rows that match the first 5 values in a list/sub-query
C. Returns rows that match any value in a list/sub-query
D. Returns the value 0 when all the rows match in a list/sub-query

Answer: C.

81.What is true about the ALL operator used for sub-queries?


(Choose the most appropriate answer.)

A. Returns rows that match all the values in a list/sub-query


B. Returns rows that match only some values in a list/sub-query
C. Returns rows only if all the values match in a list/sub-query
D. All of the above

Answer: C. '> ALL' More than the highest value returned by the subquery.
'< ALL' Less than the lowest value returned by the subquery. '< ANY' Less
than the highest value returned by the subquery. '> ANY' More than the
lowest value returned by the subquery. '= ANY' Equal to any value
returned by the subquery (same as IN). '[NOT] EXISTS' Row must match
a value in the subquery.

82.What is true about using sub-queries in INSERT statements in


Oracle?

A. They can be used in the INSERT clause without any restriction


B. They can be used in the INSERT clause only for Numeric values
C. The SELECT list of a sub-query should be the same as the column list of the
INSERT statement.
D. None of the above

Answer: C.

Examine the table structures as given below and answer the


questions 83 to 86 that follow.

SQL> DESC employees


Name Null? Type
----------------------- -------- ----------------
EMPLOYEE_ID NOT NULL NUMBER(6)
FIRST_NAME VARCHAR2(20)
LAST_NAME NOT NULL VARCHAR2(25)
EMAIL NOT NULL VARCHAR2(25)
PHONE_NUMBER VARCHAR2(20)
HIRE_DATE NOT NULL DATE
JOB_ID NOT NULL VARCHAR2(10)
SALARY NUMBER(8,2)
COMMISSION_PCT NUMBER(2,2)
MANAGER_ID NUMBER(6)
DEPARTMENT_ID NUMBER(4)
SQL> DESC departments
Name Null? Type
----------------------- -------- ----------------
DEPARTMENT_ID NOT NULL NUMBER(4)
DEPARTMENT_NAME NOT NULL VARCHAR2(30)
MANAGER_ID NUMBER(6)
LOCATION_ID NUMBER(4)

83.You need to find the details of all employees who were hired for
the job ID 'SA_REP' in the month of June, 2013. Which of the
following queries will give the required results? (Consider the
table structure as given)

A. SELECT first_name
B. FROM employees
C. WHERE employee_id =
D. ( SELECT employee_id
E. FROM employees
F. WHERE to_char(hiredate, 'MM/YYYY')= '02/1981'
G. AND job_id = 'SA_REP'
H. );
I. SELECT first_name
J. FROM employees
K. WHERE employee_id = ANY
L. ( SELECT employee_id
M. FROM employees
N. WHERE to_char(hiredate, 'MM/YYYY')= '02/1981'
O. AND job_id = 'SA_REP'
P. );
Q. SELECT first_name
R. FROM employees
S. WHERE employee_id ANY
T. ( SELECT employee_id
U. FROM employees
V. WHERE to_char(hiredate, 'MM/YYYY')= '02/1981'
W. AND job_id = 'SA_REP'
X. );
Y. SELECT first_name
Z. FROM employees
AA. WHERE employee_id exists
BB. ( SELECT employee_id
CC. FROM employees
DD. WHERE to_char(hiredate, 'MM/YYYY')= '02/1981'
EE. AND job_id = 'SA_REP'
FF. );

Answer: B.

84.Which of the following statements are equivalent?

A. SELECT employee_id , salary


B. FROM employees
C. WHERE salary < ALL (SELECT salary FROM employees WHERE department_id=100);
D. SELECT employee_id , salary
E. FROM employees WHERE salary < (SELECT min(salary) FROM employees WHERE
department_id=100);
F. SELECT employee_id
G. FROM employees
H. WHERE salary not >= ANY (SELECT salary FROM employees WHERE
department_id=100);

I. None of the above

Answer: A, B.

85.Consider the following two queries:

Query 1:
SELECT first_name
FROM employees e join departments d
ON e.department_id = d.department_id
WHERE department_name='ACCOUNTS';

Query 2:
SELECT first_name
FROM employees e
WHERE department_id = ANY (SELECT department_id FROM departments d
WHERE department_name='ACCOUNTS');

What can be said about the two statements?

A. Both the queries should generate the same result.


B. Both the queries will throw an error.
C. If there are two departments with the same name, both the queries will fail.
D. Both the queries will run successfully even if there is more than one
department named 'ACCOUNTS'.

Answer: A, D.

86.You need to display all the employees who have the highest
salary in a department 100. You fire a query as below.
SELECT E.first_name, E.last_name , E.salary
FROM employees E
WHERE E.salary > ALL (SELECT E1.salary
FROM employees E1
WHERE E.department_id =E1.department_id
AND E.department_id = 100);

What will be the outcome of the above query?

A. It executes successfully and gives the required results


B. It executes successfully but doesn't give the required output
C. It throws an ORA error on execution
D. It executes successfully and gives the required result when >ALL is replaced
with >=ALL

Answer: B, D. >ALL will not give the required result as there may be two
employees with the same salary and who are the highest earners in the
department 100

Consider table structures as shown in the exhibit and answer the


questions 87 to 89 that follow:

87.You need to fetch the first names (in a reverse alphabetical


order) of all the employees in the department ID = 100 and who
have the maximum salary in the JOB ID = 'SA_REP'. Which of the
following queries will give the required output? (Choose the most
appropriate output)

A. SELECT E.first_name, job_id , salary


B. FROM employees E
C. WHERE salary =
D. (SELECT max(salary)
E. FROM employees E1
F. WHERE E1.department_id = 100
G. GROUP BY job_id )
H. AND job_id = 'SA_REP'
I. ORDER BY first_name;
J. SELECT E.first_name, job_id , salary
K. FROM employees E
L. WHERE salary in
M. (SELECT max(salary)
N. FROM employees E1
O. where E1.department_id = 100)
P. ORDER BY first_name;
Q. SELECT E.first_name, job_id , salary
R. FROM employees E
S. WHERE salary IN
T. (SELECT max(salary)
U. FROM employees E1
V. where job_id = 'SA_REP'
W. GROUP BY job_id )
X. AND WHERE E.department_id = 100
Y. ORDER BY first_name desc;
Z. SELECT E.first_name, job_id , salary
AA. FROM employees E
BB. WHERE salary IN
CC. (SELECT max(salary)
DD. FROM employees E1
EE. WHERE E1.department_id = 100
FF. GROUP BY job_id )
GG. ORDER BY first_name ;

Answer: C.

88.In the queries given above (option C is the correct answer), you
need to display all the employees with the JOB ID 'SA_REP' who
have the maximum salary in the department 100. Which of the
following queries will give the required output?

A. SELECT E.first_name, job_id , salary


B. FROM employees E
C. WHERE salary IN
D. (SELECT max(salary)
E. FROM employees E1
F. WHERE E1.department_id = 100
G. GROUP BY job_id )
H. AND job_id = 'SA_REP'
I. ORDER BY first_name;
J. SELECT E.first_name, job_id , salary
K. FROM employees E
L. WHERE salary in
M. (SELECT max(salary)
N. FROM employees E1
O. WHERE E1.department_id = 100)
P. ORDER BY first_name;
Q. SELECT E.first_name, job_id , salary
R. FROM employees E
S. WHERE salary in
T. (SELECT max(salary)
U. FROM employees E1
V. WHERE job_id = 'SA_REP'
W. GROUP BY job_id )
X. And WHERE E.department_id = 100
Y. ORDER BY first_name desc;
Z. SELECT E.first_name, job_id , salary
AA. FROM employees E
BB. WHERE salary in
CC. (SELECT max(salary)
DD. FROM employees E1
EE. WHERE E1.department_id = 100
FF. GROUP BY job_id )
GG. ORDER BY first_name ;
Answer: A.

89.Select the query which will give you the maximum salary and
maximum comm percentage. The query should also give the
maximum comm percentage paid if the highest salaried employee
gets the maximum comm percentage.

A. SELECT employee_id, max(salary), max(commission_pct )


B. FROM employees E
C. GROUP BY salary, commission_pct ;
D. SELECT employee_id, max(salary), max(commission_pct )
E. FROM employees E
F. GROUP BY salary;
G. SELECT employee_id, max(salary)
H. FROM employees E
I. GROUP BY salary, commission_pct
J. HAVING max(commission_pct ) = 100;
K. SELECT employee_id,
L. (SELECT max(salary) FROM employees) * (SELECT max(commission_pct ) FROM
employees)
M. FROM DUAL;

Answer: D. A single-row subquery can also be nested in the outer query's


SELECT clause. In this case, the value the subquery returns is available
for every row of output the outer query generates. Typically, this technique
is used to perform calculations with a value produced from a subquery.

90.What is true about the sub-queries used in the SELECT clause


of an SQL statement?

A. These sub-queries are the same in all aspects as those used in the FROM or
WHERE clauses
B. These sub-queries have to mandatorily be single row sub-queries
C. We can use multi row operators when writing such sub-queries
D. None of the above

Answer: B.

91.What will be the outcome of the following query? (Consider the


table structure as given)
SQL> DESC employees
Name Null? Type
----------------------- -------- ----------------
EMPLOYEE_ID NOT NULL NUMBER(6)
FIRST_NAME VARCHAR2(20)
LAST_NAME NOT NULL VARCHAR2(25)
EMAIL NOT NULL VARCHAR2(25)
PHONE_NUMBER VARCHAR2(20)
HIRE_DATE NOT NULL DATE
JOB_ID NOT NULL VARCHAR2(10)
SALARY NUMBER(8,2)
COMMISSION_PCT NUMBER(2,2)
MANAGER_ID NUMBER(6)
DEPARTMENT_ID NUMBER(4)
SELECT sysdate,
(SELECT max(salary) FROM employees GROUP BY department_id )
FROM DUAL;

A. It gives the system date and the maximum salary for each department
B. It gives the maximum salary for all the departments
C. It throws an ORA error
D. It executes successfully with 0 rows

Answer: C. A Multi row sub-query cannot be used in the SELECT clause


of an SQL statement. Only a single-row subquery can be nested in the
outer query's SELECT clause.

Examine the given table structure. Consider the following query


and answer the questions 92 to 95 that follow:

SQL> DESC employees


Name Null? Type
----------------------- -------- ----------------
EMPLOYEE_ID NOT NULL NUMBER(6)
FIRST_NAME VARCHAR2(20)
LAST_NAME NOT NULL VARCHAR2(25)
EMAIL NOT NULL VARCHAR2(25)
PHONE_NUMBER VARCHAR2(20)
HIRE_DATE NOT NULL DATE
JOB_ID NOT NULL VARCHAR2(10)
SALARY NUMBER(8,2)
COMMISSION_PCT NUMBER(2,2)
MANAGER_ID NUMBER(6)
DEPARTMENT_ID NUMBER(4)
SELECT salary
FROM employees
WHERE salary > ALL (10, 20, 30);

92.Which of the following queries are equivalent to the above


query?

A. SELECT salary
B. FROM employees
C. WHERE salary >10 or salary > 20 and salary >30;
D. SELECT salary
E. FROM employees
F. WHERE salary <10 and salary < 20 and salary <30;
G. SELECT salary
H. FROM employees
I. WHERE salary >10 and salary > 20 and salary >30;
J. SELECT salary
K. FROM employees
L. WHERE salary >10 and salary > 20 or salary < 30;

Answer: C. The question shows the ALL clause in a simplified manner


when it is followed by a list.

93. If in the above query the list (10,20,30) is replaced by a sub-


query, which of the following queries will give the required output
for the department number 100?

A. SELECT E.salary
B. FROM employees E
C. WHERE E.salary > (SELECT E1.salary
D. FROM employees E1
E. WHERE E1.department_id = 100);
F. SELECT E.salary
G. FROM employees E
H. WHERE E.salary >ALL (SELECT E1.salary
I. FROM employees E1
J. WHERE E1.department_id = 100);
K. SELECT E.salary
L. FROM employees E
M. WHERE E.salary = (SELECT E1.salary
N. FROM employees E1
O. WHERE E1.department_id = 100);
P. SELECT E.salary
Q. FROM employees E
R. WHERE E.salary >= (SELECT E1.salary
S. FROM employees E1
T. WHERE E1.department_id = 100);

Answer: B. The question shows the ALL clause in a simplified manner


when it is followed by a sub-query

94.With respect to the question 14 above, what among the


following will be an equivalent query if ALL has to be replaced with
ANY?

A. SELECT E.salary
B. FROM employees E
C. WHERE NOT EXISTS (E.salary =ANY (SELECT E1.salary
D. FROM employees E1
E. WHERE E1.department_id = 100);
F. SELECT E.salary
G. FROM employees E
H. WHERE E.salary >ANY (SELECT E1.salary
I. FROM employees E1
J. WHERE E1.department_id = 100);
K. SELECT E.salary
L. FROM employees E
M. WHERE E.salary =ANY (SELECT E1.salary
N. FROM employees E1
O. WHERE E1.department_id = 100);
P. SELECT E.salary
Q. FROM employees E
R. WHERE NOT ( E.salary <= ANY (SELECT E1.salary
S. FROM employees E1
T. WHERE E1.department_id = 100));

Answer: D. The NOT operator used while using '<= ANY' is used for
negation of the results returned by the sub-query

95.With respect to the question 94, if the operator ANY is not to be


used, which of the following queries will be correct?

A. SELECT E.salary
B. FROM employees E
C. WHERE NOT EXISTS (E.salary = ANY (SELECT E1.salary
D. FROM employees E1
E. WHERE E1.department_id = 100);
F. SELECT E.salary
G. FROM employees E
H. WHERE NOT EXISTS (SELECT E1.salary
I. FROM employees E1
J. WHERE E1.department_id = 100
K. And E.salary <= E1.salary);

L. Either A or B
M. None of the above

Answer: B. Correlated subquery references a column in the outer query


and executes the subquery once for every row in the outer query;and the
EXISTS operator is used to test whether the relationship or link is present.
An Uncorrelated subquery executes the subquery first and passes the
value to the outer query.

Examine the given table structures. Consider the following query


and answer the questions 96 to 98 that follow:

SQL> DESC employees


Name Null? Type
----------------------- -------- ----------------
EMPLOYEE_ID NOT NULL NUMBER(6)
FIRST_NAME VARCHAR2(20)
LAST_NAME NOT NULL VARCHAR2(25)
EMAIL NOT NULL VARCHAR2(25)
PHONE_NUMBER VARCHAR2(20)
HIRE_DATE NOT NULL DATE
JOB_ID NOT NULL VARCHAR2(10)
SALARY NUMBER(8,2)
COMMISSION_PCT NUMBER(2,2)
MANAGER_ID NUMBER(6)
DEPARTMENT_ID NUMBER(4)
SELECT salary
FROM employees
WHERE salary > ANY (10, 20, 30);

96. Which of the following queries are equivalent to the above


query?

A. SELECT salary
B. FROM employees
C. WHERE salary >10 or salary > 20 and or >30;
D. SELECT salary
E. FROM employees
F. WHERE salary <10 and salary < 20 and salary <30;
G. SELECT salary
H. FROM employees
I. WHERE salary >10 and salary > 20 or salary >30;
J. SELECT salary
K. FROM employees
L. WHERE salary >10 and salary > 20 or salary < 30;

Answer: A. The question shows the ANY clause in a simplified manner


when it is followed by a list.
97. In the above query, if the list (10, 20, 30) is replaced by a sub-
query, which of the following queries will give the required output
for the department number 100?

A. SELECT E.salary
B. FROM employees E
C. WHERE E.salary > (SELECT E1.salary
D. FROM employees E1
E. WHERE E1.department_id = 100);
F. SELECT E.salary
G. FROM employees E
H. WHERE E.salary >ANY (SELECT E1.salary
I. FROM employees E1
J. WHERE E1.department_id = 100);
K. SELECT E.salary
L. FROM employees E
M. WHERE E.salary = (SELECT E1.salary
N. FROM employees E1
O. WHERE E1.department_id = 100);
P. SELECT E.salary
Q. FROM employees E
R. WHERE E.salary >= (SELECT E1.salary
S. FROM employees E1
T. WHERE E1.department_id = 100);

Answer: B. The question shows the ANY clause in a simplified manner


when it is followed by a sub-query

98.With respect to the question 97 above, what among the


following will be an equivalent query if ANY is removed?

A. SELECT E.salary
B. FROM employees E
C. WHERE NOT EXISTS (E.salary =ANY (SELECT E1.salary
D. FROM employees E1
E. WHERE E1.department_id = 100);
F. SELECT E.salary
G. FROM employees E
H. WHERE EXISTS (SELECT E1.salary
I. FROM employees E1
J. WHERE E1.department_id = 100
K. And E.salary >E1.salary);
L. SELECT E.salary
M. FROM employees E
N. WHERE EXISTS (SELECT E1.salary
O. FROM employees E1
P. WHERE E1.department_id = 100
Q. );
R. SELECT E.salary
S. FROM employees E
T. WHERE IN (SELECT E1.salary
U. FROM employees E1
V. WHERE E1.department_id = 100);

Answer: B. The EXISTS operator can substitute the ANY operator.


Correlated subquery references a column in the outer query and executes
the subquery once for every row in the outer query;and the EXISTS
operator is used to test whether the relationship or link is present.

99.Examine the given table structure. How many rows will get
generated if the sub-query mentioned returns 0 rows?

SQL> DESC employees


Name Null? Type
----------------------- -------- ----------------
EMPLOYEE_ID NOT NULL NUMBER(6)
FIRST_NAME VARCHAR2(20)
LAST_NAME NOT NULL VARCHAR2(25)
EMAIL NOT NULL VARCHAR2(25)
PHONE_NUMBER VARCHAR2(20)
HIRE_DATE NOT NULL DATE
JOB_ID NOT NULL VARCHAR2(10)
SALARY NUMBER(8,2)
COMMISSION_PCT NUMBER(2,2)
MANAGER_ID NUMBER(6)
DEPARTMENT_ID NUMBER(4)
SELECT E.salary
FROM employees E
WHERE E.salary > ANY ( select E1.salary FROM employees E1 where E1.department_id
= 100);

A. 1 row
B. No rows
C. Either A or B
D. None of the above

Answer: B. If the sub-query returns zero rows, the '> ANY' condition
evaluates to FALSE, hence "No rows" are returned.

100. A subquery must be placed in the outer query's HAVING


clause if:

A. The inner query needs to reference the value returned to the outer query.
B. The value returned by the inner query is to be compared to grouped data in
the outer query.
C. The subquery returns more than one value to the outer query.
D. None of the above. Subqueries can't be used in the outer query's HAVING
clause.

Answer: B. A HAVING clause is used when the group results of a query


need to be restricted based on some condition. If a subquery's result must
be compared with a group function, you must nest the inner query in the
outer query's HAVING clause.

Q2. What are the fields in a bug report?


Following important fields should be included in a good bug report:
1. A unique ID
2. Defect description a short describing what the bug is
3. Steps to reproduce details about how to arrive at the error, exact test data, the
time at which defect was found(if applicable) environment any information that
will help re-encounter the issue
4. Module/section of the application (if applicable)
5. Severity
6. Screenshot
7. Responsible QA in case of any follow up questions regarding this issue
Agile Model Pros and Cons
Agile methods are being widely accepted in the software world recently,
however, this method may not always be suitable for all products. Here
are some pros and cons of the agile model.

Following table lists out the pros and cons of Agile Model:

Pros Cons

Is a very realistic approach to Not suitable for handling complex


software development dependencies.

Promotes teamwork and More risk of sustainability,


cross training. maintainability and extensibility.

Functionality can be An overall plan, an agile leader and


developed rapidly and agile PM practice is a must without
demonstrated. which it will not work.

Resource requirements are Strict delivery management dictates


minimum. the scope, functionality to be
delivered, and adjustments to meet
Suitable for fixed or changing
the deadlines.
requirements
Depends heavily on customer
Delivers early partial working
interaction, so if customer is not
solutions.
clear, team can be driven in the
wrong direction.
Good model for
environments that change
There is very high individual
steadily.
dependency, since there is minimum
documentation generated.
Minimal rules,
documentation easily
Transfer of technology to new team
employed.
members may be quite challenging
due to lack of documentation.
Enables concurrent
development and delivery
within an overall planned
context.

Little or no planning required

Easy to manage

Gives flexibility to developers

You might also like