Getting the last record in SQL in WHERE condition

后端 未结 9 2258
借酒劲吻你
借酒劲吻你 2021-02-15 04:24

i have loanTable that contain two field loan_id and status

loan_id status
==============
1       0
2       9
1       6
         


        
9条回答
  •  离开以前
    2021-02-15 04:44

    Does your table happen to have a primary id or a timestamp? If not then what you want is not really possible.

    If yes then:

        SELECT TOP 1 status
        FROM loanTable
        WHERE loan_id = 1
        ORDER BY primaryId DESC
        -- or
        -- ORDER BY yourTimestamp DESC
    

提交回复
热议问题