QuestionQ18

VerifiedManipulating Data

View the exhibit and review the structures of the employees and departments tables.

Question Image

You want to update the employees table as follows:

  • Update only employees who work in Boston or Seattle (locations 2900 and 2700).
  • Set department_id for these employees to the department_id that corresponds to London (location_id 2100).
  • Set the employees' salary in iocation_id 2100 to 1.1 times their department's average salary.
  • Set the employees' commission in iocation_id 2100 to 1.5 times their department's average commission.

You issue this command:

Question Image

What is the result?

Explanation

Oracle permits an UPDATE statement to assign multiple columns from a subquery when the subquery returns the same number of values. The aggregate subquery returns one row, so the statement executes. However, its employees and departments references are not joined or correlated to the row being updated, so the AVG(salary) and AVG(commission) values are overall averages for the Cartesian product of the selected locations rather than averages for each affected employee's department. The resulting values are therefore incorrect.

Learn more

Community Discussion

No comments yet. Be the first to start the discussion!