locked
query for last 5 records in sql server 2008 RRS feed

  • Question

  • User29410129 posted

    Want to retrieve last 8 rows  from multiple table. My tables are mention below

    Select Top 8 * from Lecture lec inner join Resource res on lec.lec_ID = res.lec_ID
    inner join ResourceType rt on rt.rt_ID = res.rt_ID
    inner join Subject sub on sub.subject_ID = lec.subject_ID

    Waiting for your feedback.

    Tuesday, December 29, 2015 5:22 AM

Answers

  • User1724605321 posted

    Hi DanyalHaider,

    For example :

    SELECT TOP 5 *
    FROM MyTable
    ORDER BY Id DESC

    Best Regards,

    Nan Yu

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, December 29, 2015 7:55 AM

All replies

  • User-62323503 posted

    you should have incrementing Id or datetime stamp, then you can use order by col desc to fetch last n records

    Tuesday, December 29, 2015 5:43 AM
  • User29410129 posted

    have you any example related this problem?

    Tuesday, December 29, 2015 6:52 AM
  • User1724605321 posted

    Hi DanyalHaider,

    For example :

    SELECT TOP 5 *
    FROM MyTable
    ORDER BY Id DESC

    Best Regards,

    Nan Yu

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, December 29, 2015 7:55 AM