Getting the last record in SQL in WHERE condition

后端 未结 9 2251
借酒劲吻你
借酒劲吻你 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:32

    But if last = last inserted, that's not possible for current schema, until a PK addition:

    select top 1 status, loan_id
    from loanTable
    where loan_id = 1
    order by id desc -- PK
    

提交回复
热议问题