我需要获取包含值的条目的 ID。
这是我用过的:
SET @ValuationId = (SELECT ValuationId FROM dbo.Valuation WHERE ValuationPropertyId = @ValuationPropertyId)
上面的问题是它选择了多个值,我可以用什么来让它选择最新的值?
这是我收到的错误消息:
Msg 512, Level 16, State 1, Procedure GetLatestValuationOfPropIdThenCallUpdateComparibleSalesInfo, Line 15 Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.
最佳答案
使用MAX()
SET @ValuationId = (SELECT MAX(ValuationId)
FROM dbo.Valuation
WHERE ValuationPropertyId = @ValuationPropertyId)
或
SET @ValuationId = (SELECT TOP 1 ValuationId
FROM dbo.Valuation
WHERE ValuationPropertyId = @ValuationPropertyId
ORDER BY ValuationId DESC)
关于sql - 选择最新条目的Id,值为***,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14953415/