我有以下查詢:使用ORDER BY的SQL UPDATE TOP?
UPDATE TOP (@MaxRecords) Messages
SET status = 'P'
OUTPUT inserted.*
FROM Messages
where Status = 'N'
and InsertDate >= GETDATE()
郵件表有優先權列,我想先seleci高優先級消息。所以我需要一個ORDER BY。但是,在更新運行之前,我不需要對排序後的輸出進行排序。
據我所知,不可能將ORDER BY添加到UPDATE語句。任何其他想法?
m。
[SQL更新top1行查詢]的可能重複(http://stackoverflow.com/questions/3860975/sql-update-top1-row-query) – fabriciorissetto
可能重複[如何使用ms sql進行更新和排序](http://stackoverflow.com/questions/655010/how-to-update-and-order-by-using-ms-sql) – Athafoud