English 中文(简体)
载有第二表数据的最新表格
原标题:Update table rows with data from second table

我正试图从一个二级表中的数据中更新一个总表中的具体数据。

我有一个10万列的主食,其中一栏为“UniqueCode”,一部独特的阿尔法法典,另一栏为“Data”,其中载有一系列案文。 我有大约2 000个牢房的二级,有2个栏,即“新元”和“住房”。 “新数据”是另一条插图,“文化”是“阿尔法法典”,相当于总表格中的“大学”。

我想更新主文中的“数据”一栏,因为从中学到的《阿尔法法典》与《阿尔法法典》平等,因此与第二桌的“新数据”相同。

如果在努力寻找办法,将不胜感激。

最佳回答
UPDATE MasterTable
SET 
    Data = s.New_Data
FROM MasterTable m
INNER JOIN SecondaryTable s ON m.UniqueCode = s.Code
问题回答
update master
set data = s.new_data
from master m
inner join second s on m.alphacode = s.code 

update master
set data = s.new_data
from master m, second s
where m.alphacode = s.code 




相关问题
How to write this T-SQL WHERE condition?

I ve got two tables: TableA Col1 Col2 TableB Col3 Col4 I want to join them together: SELECT * from TableA join TableB ON (...) Now, in place of ... I need to write an expression ...

Customer and Order Sql Statement

TSQL query to select all records from Customer that has an Order and also select all records from customer that does not have an Order. The table Customer contains a primary key of CustomerID. The ...

Recommended way of querying multiple Versioned tables

Have a win 2003 box with MSSQL 2005 running on it. There is a database which is populated every morning with new/modified SalesOrder made the previous day. The database has several tables: SalesOrder, ...

update duplicate record

I have a table with the following fields Id Name IsPublic i need to write a sql query that updates IsPublic to false where name has a duplicate. Only one of the duplicates should have IsPublic = ...

Define variable to use with IN operator (T-SQL)

I have a Transact-SQL query that uses the IN operator. Something like this: select * from myTable where myColumn in (1,2,3,4) Is there a way to define a variable to hold the entire list "(1,2,3,4)"? ...

Selecting records during recursive stored procedure

I ve got a content management system that contains a hierarchical structure of categories, with sub-categories subject to different ordering options at each level. Currently, that s retrieved by a (...

热门标签