The questions can come in any order, so make sure you are selecting right option for all questions.
Which of the following are not valid subquery type:(b) All are valid
(b) False
(c) Returns rows that match any value in a list/sub-query
(b) The sub-queries which reference a column used in the main query are called co-related sub-queries
(a) once
(b) correlated
(d) SELECT first_name, last_name FROM employees WHERE department = (SELECT department FROM employees WHERE first_name = 'Jessica' AND last_name = 'Butcher' AND employee_id = 40) AND salary > (SELECT salary FROM employees WHERE first_name = 'Jessica' AND last_name = 'Butcher' AND employee_id = 40);
(c) join
(d) select
(d) By writing a SELECT statement embedded in the clause of another SELECT statement
SELECT a.EmployeeID
FROM HumanResources.Employee a
WHERE a.ContactID IN
(
SELECT b.ContactID
FROM Person.Contact b
WHERE b.Title = 'Mrs.'
)
GO
(b) Noncorrelated Subquery
(d) SELECT first_name, last_name FROM employees WHERE dept_id = (SELECT dept_id FROM employees WHERE first_name = 'Jessica' AND last_name = 'Butcher' AND dept_id = 100 AND emp_id = 40);
(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');
(c) 0
A) UPDATE CUSTOMERS SET SALARY = SALARY * 0.25
WHERE AGE NOT IN (SELECT AGE FROM CUSTOMERS
WHERE AGE >= 27 );
B) UPDATE CUSTOMERS SET SALARY = SALARY * 0.25
WHERE AGE IN (SELECT AGE FROM CUSTOMERS
WHERE AGE >= 27 );
C) UPDATE CUSTOMERS
WHERE AGE IN (SELECT AGE FROM CUSTOMERS
WHERE AGE >= 27 ) SET SALARY = SALARY * 0.25;
(b) B
SELECT employee_id, first_name, last_name, job_id
FROM employees
WHERE job_id = (SELECT job_id FROM employees);
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?
(a) WHERE job_id = (SELECT job_id FROM employees WHERE employee_id = 210);
SELECT employee_id, first_name, last_name, job_id
FROM employees
WHERE job_id = (SELECT job_id FROM employees WHERE employee_id < 210);
While executing, the above query will throw an error.
Choose the query that will not throw any error.
(b) SELECT employee_id, first_name, last_name, job_id FROM employees WHERE job_id IN (SELECT job_id FROM employees WHERE employee_id < 210);
(b) 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
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
(c) C
SELECT first_name, last_name, salary, commission_pct
FROM employees
WHERE salary < ANY (SELECT salary
FROM employees
WHERE department_id = 100)
What will be the outcome of the query given above if the < ANY operator is replaced with = ANY operator, if we assume that the department 100 has more employees?
(a) It will treat each value of the salary returned from the sub-query as it does with IN operator
(b) The value returned by the inner query is to be compared to grouped data in the outer query.