Let's say you use the UPDATE statement in a table, but the information you put in this base table is taken from some other auxiliary table. Usually, you join the data and do not expect the rows in the expression of the UPDATE FROM statement to be multiplied, maintaining that one new row is matched with one old row in the base table.
But I was wondering what would happen if your JOIN table was somehow ambiguous, for example, you could not take into account each mapping of base objects to only one merged object. Or if you did something meaningless, for example, join the base table to the table of your children and update the base table using this information. How to choose it? Now in one row of the table there are several rows.
In SQL Server 2005, I ran a statement like this, and seemed to select the first row in each set. But that seems wrong to me. Isn't that a mistake? Why is this the desired behavior?
Code example
update bundles_denormalized set category = c.description
from bundles_denormalized b
left join categories c
on b.category_id = c.id
update bundles_denormalized set category = p.description
from bundles_denormalized b
left join products p
on b.id = p.bundle_id
source
share