SQL ORDER BY on Update- update last record with condition

后端 未结 1 1617
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-25 09:18

I am trying to update the last record of table Log (the field with the latest TimeAccessed) given that TimeExited is null, and the computername is the same as the \"cm\" paramet

相关标签:
1条回答
  • 2021-01-25 09:53

    Access SQL doesn't use LIMIT n it uses TOP n, and as mentioned in the other question cited in the comments to your question, you aren't allowed to use TOP in the way you've described. Instead, you'll need to do something along these lines:

    UPDATE Log 
    SET TimeExited = CloseTime
    WHERE TimeExited IS NULL 
        AND ComputerName='r2d2'
        AND TimeAccessed IN
            (
                SELECT TOP 1 TimeAccessed
                FROM Log
                WHERE TimeExited IS NULL 
                    AND ComputerName='r2d2'
                ORDER BY TimeAccessed DESC
            )
    
    0 讨论(0)
提交回复
热议问题