我无法更新SQL中的表。 我有两张桌子。更新表ID与其他表中的相关ID
SYSTEMOBJECT表:
Id SystempointID
1 NULL
2 NULL
3 NULL
SystemPoint表:
Id othercolumn
11 testpoint
12 testpoint2
13 testpoint 3
我需要与systempoint标识更新SYSTEMOBJECT表。他们需要按顺序匹配。这是我的SYSTEMOBJECT表如何必须是:
SYSTEMOBJECT表:
Id SystempointID
1 11
2 12
3 13
我有这些ID的500+,所以我想知道我必须使用,以填补我SYSTEMOBJECT表与哪个查询系统点ID自动。最高的系统点ID必须与最高的系统对象ID相匹配。
我曾尝试这样的代码:
UPDATE [demo].[dbo].[SystemObject]
SET SystemPointId = (SELECT [demo].[dbo].[SystemPoint].[Id] FROM [demo].[dbo].[SystemPoint]
WHERE SystemPoint.Id = (SELECT MAX(ID) FROM [demo].[dbo].[SystemPoint]))
当我使用此代码我在SYSTEMOBJECT列得到所有行的一个值(最高systempoint ID)。我只想填写有NULL值,这样我不会覆盖我的价值观已经填行
你要填写最大值或独特的价值。 – 2015-03-03 14:01:48
最大值@ankit Bajpai – user3142048 2015-03-03 14:04:34