Updating and join on multiple rows, which row’s value is used?

I don’t think there are rules for this case and you cannot depend on a particular outcome.

If you’re after a specific row, say the latest one, you can use apply, like:

UPDATE  a
SET     a.Value = b.Value
FROM    tableA AS a
CROSS APPLY
        (
        select  top 1 *
        from    tableB as b
        where   b.id = a.id
        order by
                DateColumn desc
        ) as b

Leave a Comment

techhipbettruvabetnorabahisbahis forumuedusedueduedusedueduedueduseduedu