1. Home
  2. Data Science
  3. SQL for Data Analysis
  4. UPDATE t SET v = s.v FROM src s WHERE t.id = s.id carries…

Added 30 Nov -0001

UPDATE t SET v = s.v FROM src s WHERE t.id = s.id carries which hazard when several src rows share one id?

  1. It updates every row of t, since the WHERE clause applies to src only
  2. It requires a unique index on t.id, or the whole update is rolled back
  3. If several source rows match a target row, one arbitrary value wins out Correct answer
  4. The statement fails whenever more than one source row matches a target row here

Correct answer

C. If several source rows match a target row, one arbitrary value wins out

18 views

MCQSEXAM

Explanation

UPDATE ... FROM joins the target to a source table, and PostgreSQL does not define which source row is used when several match the same target row: the result is non-deterministic rather than an error. The usual cure is a subquery that aggregates to exactly one row per key before joining. MySQL's multi-table UPDATE and SQL Server's UPDATE with a join behave the same way.

Reference

Asked in: NTS, PPSC IT, Interviews

Preparing for an exam?

Doubts & discussion

Not sure why the answer is C? Ask here and get an explanation.

Ask a doubt about this MCQ

Shown after review. No links please.

More SQL for Data Analysis MCQs

Practise all SQL for Data Analysis MCQs

Similar MCQs