SQLTB 5

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Lab exercises no.

5
1. What is a subquery in SQL?
A) A query that is executed before the main query.
B) A query that is executed after the main query.
C) A query that is nested inside another query.
D) A query that is used to filter the results of another query.

2. Which of the following is an example of a subquery?


A) SELECT * FROM employees
B) SELECT * FROM employees WHERE salary > 5000
C) SELECT * FROM departments WHERE department_id IN (SELECT department_id
FROM employees WHERE salary > 5000)
D) SELECT * FROM departments JOIN employees ON departments.department_id =
employees.department_id

3. What is the purpose of a subquery?


A) To join multiple tables together.
B) To filter the results of a query based on a condition.
C) To group the results of a query.
D) To sort the results of a query.

4. What does the following SQL query return? SELECT last_name, salary FROM
employees WHERE salary > (SELECT salary FROM employees WHERE
last_name = 'Abel');
A) Last names and salaries of employees above average salary of those with last name Abel.
B) The last name and salary of Abel's manager
C) The last names and salaries of all employees who earn more than Abel
D) The last name and salary of the employee with the highest salary in the company

5. Which of the following statements is true about the following SQL query? SELECT
last_name, job_id, salary FROM employees WHERE salary = (SELECT
MIN(salary) FROM employees);
A) It selects the first name, job id, and salary of all employees.
B) It selects the last name, job id, and salary of all employees.
C) It selects the last name, job id, and salary of the employee with the lowest salary.
D) It selects the last name, job id, and salary of the employee with the highest salary.
6. Which of the following statements is true about the following SQL query? SELECT
last_name FROM employees WHERE salary < ANY (SELECT salary FROM
employees WHERE job_id = 'IT_PROG');
A) Returns last name of all employees in the IT department.
B) Returns last name of employees whose salary < any employee in the IT department.
C) Returns last name of employees whose salary > any employee in the IT department.
D) Returns last name of employees whose salary is < the average salary of the IT department.

1|Page
7. Which of the following statements is true about the above SQL query? SELECT
employee_id, salary FROM employees WHERE salary < ALL (SELECT salary
FROM employees WHERE job_id = 'IT_PROG');
A) It selects the employee ID and salary of employees whose salary < all employee in the IT
department.
B) It selects the employee ID and salary of employees whose salary > all any employee in the
IT department.
C) It selects the employee ID and salary of all employees in the IT department.
D) It selects the employee ID and salary of employees whose salary < the average salary of
the IT department.

8. Which of the following operators can be used with a subquery?


A) IN
B) NOT IN
C) EXISTS
D) All of the above

9. Which of the following statements is true about a subquery?


A) A subquery can only return one value.
B) A subquery can be used to update data in a table.
C) A subquery must be enclosed in parentheses.
D) A subquery can only be used in the SELECT statement.

2|Page

You might also like