How to find last value from Ms Sql



  • I have an example table like this:

    ID UserId Name
    1 00009 Jomy
    2 00012 Tomy
    3 00012 Tomy
    4 00012 Tomy
    5 00009 Jomy

    I want to get the last value of UserId = 00012, (UserId from ID number 4). I have tried several queries like this:

    SELECT TOP 1 * 
    FROM TABLE 
    WHERE UserId = 00012 
    ORDER BY UserId DESC
    

    But it didn't work. Can you guys help me to find the correct query?



  • i have find the answer base on Zhorov answer i put the query bellow

    SELECT TOP 1 ApiType FROM dbo.ApiUserInfo Where UserId=@UserId ORDER BY AddTime DESC




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2