Forums before death by AOL, social media and spammers... "We can't have nice things"
|    comp.databases.ms-sqlserver    |    Notorious Rube Goldberg contraption    |    19,505 messages    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
|    Message 19,345 of 19,505    |
|    Anton Shepelev to All    |
|    UPDATE FROM    |
|    19 Jul 21 12:14:48    |
   
   From: anton.txt@g{oogle}mail.com   
      
   Hello, all. The MSSQL documentation for `UPDATE FROM' is   
   not very clear on how the update source should be specified   
   and how its rows are matched against those of the table   
   being updated. I think the following methods are equivalent   
   and correct:   
      
    -- 1.   
    UPDATE my_alias   
    SET col = data_tab.col   
    FROM upd_tab my_alias   
    JOIN data_tab ON data_tab.code = my_alias.code   
      
    -- 2.   
    UPDATE upd_tab   
    SET col = data_tab.col   
    FROM upd_tab my_alias   
    JOIN data_tab ON data_tab.code = my_alias.code   
      
   But in some old code that seems to have been working for   
   about ten years I have found an `UPDATE' with the following   
   structure:   
      
    -- 3.   
    UPDATE upd_tab   
    SET col = data_tab.col   
    FROM data_tab   
    WHERE data_tab.code = my_alias.code   
      
   which, unlike the previous two commands, works non-   
   deterministically, although there are no more than one row   
   in data_tab from each row in upd_tab. Is it because the FROM   
   clause does not mention upd_tab, whereas it must? If so,   
   how is the WHERE predicate above interpreted and how does it   
   affect the result?   
      
   --   
   () ascii ribbon campaign - against html e-mail   
   /\ http://preview.tinyurl.com/qcy6mjc [archived]   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
(c) 1994, bbs@darkrealms.ca