Update Query with INNER JOIN between tables in 2 different databases on 1 server

后端 未结 11 1262
梦如初夏
梦如初夏 2020-12-08 09:29

Need some SQL syntax help :-)

Both databases are on the same server

db1 = DHE
db2 = DHE_Import

UPDATE DHE.dbo.tblAccounts 
INNER JOIN DHE_Import.dbo         


        
相关标签:
11条回答
  • 2020-12-08 09:43

    Following is the MySQL syntax:

    UPDATE table1 
    INNER JOIN table2 ON table1.field1 = table2.field2
    SET table1.field3 = table2.field4 
    WHERE ...... ;
    

    http://geekswithblogs.net/faizanahmad/archive/2009/01/05/join-in-sql-update--statement.aspx

    0 讨论(0)
  • 2020-12-08 09:48

    It is very simple to update using Inner join query in SQL .You can do it without using FROM clause. Here is an example :

        UPDATE customer_table c 
    
          INNER JOIN  
              employee_table e
              ON (c.city_id = e.city_id)  
    
        SET c.active = "Yes"
    
        WHERE c.city = "New york";
    
    0 讨论(0)
  • 2020-12-08 09:54
    UPDATE table1 a
     inner join  table2 b on (a.kol1=a.b.kol1...)
    SET a.kol1=b.kol1
    WHERE 
    a.kol1='' ...
    

    for me until the syntax worked -MySQL

    0 讨论(0)
  • 2020-12-08 09:58

    Should look like this:

    UPDATE DHE.dbo.tblAccounts
       SET DHE.dbo.tblAccounts.ControllingSalesRep = 
           DHE_Import.dbo.tblSalesRepsAccountsLink.SalesRepCode
      from DHE.dbo.tblAccounts 
         INNER JOIN DHE_Import.dbo.tblSalesRepsAccountsLink 
            ON DHE.dbo.tblAccounts.AccountCode =
               DHE_Import.tblSalesRepsAccountsLink.AccountCode 
    

    Update table is repeated in FROM clause.

    0 讨论(0)
  • 2020-12-08 09:58

    which may be useful

    Update
        A INNER JOIN B ON A.COL1=B.COL3
    SET
        A.COL2='CHANGED', A.COL4=B.COL4,......
    WHERE ....;
    
    0 讨论(0)
提交回复
热议问题