100% found this document useful (1 vote)
2K views

Database Programming Section 10 Quiz

The document is a database programming quiz with 15 multiple choice questions covering topics like: - The purpose of the WITH clause in SQL queries - Using comparison operators like <, =, <> with single-row subqueries - The difference between single-row and multiple-row subqueries - How NULL values returned from a subquery can affect the results of the outer query The majority of the questions deal with concepts around using subqueries to filter records in the outer query based on conditions evaluated in the subquery.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
2K views

Database Programming Section 10 Quiz

The document is a database programming quiz with 15 multiple choice questions covering topics like: - The purpose of the WITH clause in SQL queries - Using comparison operators like <, =, <> with single-row subqueries - The difference between single-row and multiple-row subqueries - How NULL values returned from a subquery can affect the results of the outer query The majority of the questions deal with concepts around using subqueries to filter records in the outer query based on conditions evaluated in the subquery.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

Database Programming Section 10 Quiz

Section 10 Quiz
(Answer all questions in this section)

1. The WITH clause is a way of creating extra tables in the


database. (True or False?) Mark for Review
(1) Points

True

False (*)

[Correct] Correct

2. The WITH clause enables a SELECT statement to define


the subquery block at the start of the query, process the block just
once, label the results, and then refer to the results multiple times.
True or False? Mark for Review
(1) Points
True (*)

False

[Correct] Correct

3. Which statement is false? Mark for Review


(1) Points

The WITH clause makes the query simple to read.

The WITH clause stores the results for the user who runs the query.

The WITH clause retrieves the results of one or more query blocks.
The WITH clause decreases performance. (*)

[Correct] Correct

4. What will the following statement return:

SELECT employee_id, last_name


FROM employees
WHERE salary =
(SELECT MIN(salary)
FROM employees
GROUP BY department_id);
Mark for Review
(1) Points

A list of first_names and salaries of employees in Department 50

Nothing. It is an invalid statement. (*)


A list of last_names and salaries of employees grouped by
department_id.

A list of last_names and salaries of employees

[Correct] Correct

5. Which operator can be used with subqueries that return only


one row? Mark for Review
(1) Points

LIKE (*)

ALL

ANY
IN

(Answer all questions in this section)

6. What will the following statement return:

SELECT last_name, salary


FROM employees
WHERE salary < (SELECT salary
FROM employees
WHERE employee_id = 103);
Mark for Review
(1) Points

A list of last_names and salaries of employees who make more


than employee 103

A list of last_names and salaries of employees who make less than


employee 103 (*)
A list of first_names and salaries of employees making less than
employee 103

Nothing. It is an invalid statement.

[Correct] Correct

7. Which statement about the <> operator is true? Mark for


Review
(1) Points

The <> operator can be used when a single-row subquery returns


only one row. (*)

The <> operator is NOT a valid SQL operator.

The <> operator returns the same result as the ANY operator in a
subquery.
The <> operator CANNOT be used in a single-row subquery.

[Correct] Correct

8. Which comparison operator can only be used with a single-


row subquery? Mark for Review
(1) Points

IN

<> (*)

ANY

ALL
[Correct] Correct

9. The result of this statement will be:

SELECT last_name, job_id, salary, department_id


FROM employees
WHERE job_id =
(SELECT job_id
FROM employees
WHERE employee_id = 141) AND
department_id =
(SELECT department_id
FROM departments
WHERE location_id =1500);
Mark for Review
(1) Points

Only the employees whose job id matches employee 141 and who
work in location 1500 (*)
An error since you canメt get data from two tables in the same
subquery

All employees from Location 1500 will be displayed

All employees with the department id of 141

[Correct] Correct

10. Evaluate the structure of the EMPLOYEES and


DEPART_HIST tables:

EMPLOYEES
EMPLOYEE_ID NUMBER(9)
LAST_NAME VARCHAR2(25)
FIRST_NAME VARCHAR2(25)
DEPARTMENT_ID NUMBER(9)
MANAGER_ID NUMBER(9)
SALARY NUMBER(7,2)
DEPART_HIST:
EMPLOYEE_ID NUMBER(9)
OLD_DEPT_ID NUMBER(9)
NEW_DEPT_ID NUMBER(9)
CHANGE_DATE DATE

You want to generate a list of employees who are in department 10,


but used to be in department 15. Which query should you use?
Mark for Review
(1) Points

SELECT employee_id, last_name, first_name, department_id


FROM employees
WHERE (employee_id, department_id) IN
(SELECT employee_id, dept_id
FROM employees
WHERE old_dept_id = 15);

SELECT employee_id, last_name, first_name, department_id


FROM employees
WHERE (employee_id, department_id) IN
(SELECT employee_id, new_dept_id
FROM depart_hist
WHERE old_dept_id = 15) AND new_dept_id = 10;

(*)

SELECT employee_id, last_name, first_name, department_id


FROM employees
WHERE (employee_id, department_id) =
(SELECT employee_id, new_dept_id
FROM depart_hist
WHERE new_dept_id = 15);

SELECT employee_id, last_name, first_name, department_id


FROM employees
WHERE (employee_id) IN
(SELECT employee_id
FROM employee_hist
WHERE old_dept_id = 15);

(Answer all questions in this section)


11. A multiple-row operator expects how many values?
Mark for Review
(1) Points

One or more (*)

Only one

Two or more

None

[Correct] Correct

12. Which operator or keyword cannot be used with a multiple-


row subquery? Mark for Review
(1) Points
ALL

ANY

>

= (*)

[Correct] Correct

13. What would happen if you attempted to use a single-row


operator with a multiple-row subquery? Mark for Review
(1) Points

The data returned may or may not be correct.


An error would be returned. (*)

No rows will be selected.

All the rows will be selected.

[Correct] Correct

14. Evaluate this SELECT statement:

SELECT player_id, name


FROM players
WHERE team_id IN
(SELECT team_id
FROM teams
WHERE team_id > 300 AND salary_cap > 400000);

What would happen if the inner query returned a NULL value?


Mark for Review
(1) Points

All the rows in the PLAYER table would be returned by the outer
query.

No rows would be returned by the outer query. (*)

A syntax error in the outer query would be returned.

A syntax error in the inner query would be returned.

[Correct] Correct

15. There can be more than one subquery returning


information to the outer query. True or False? Mark for Review
(1) Points
True (*)

False

You might also like