locked
how to get last 10 records from SqlDataSource RRS feed

  • Question

  • User231953124 posted

    Hi all,

    this is more SQL related question than ASP, however..

    I want to show in GridView last 10 records from SqlDataSource.

    SELECT TOP 10 - returns first 10 records, but I want the exact opposite: get last 10.

    I tried also command:  SelectCommand="SELECT * FROM [Transaction] ORDER BY [IDtrans] LIMIT 10" but got an error Incorrect syntax near 'LIMIT'.

    Any idea how to do it?

    Thanks Mira

    Friday, January 13, 2012 7:16 AM

Answers

  • User-1360095595 posted

    Try: SELECT TOP 10 * FROM [Transaction] ORDER BY [IDtrans] DESC

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, January 13, 2012 7:27 AM

All replies

  • User-1360095595 posted

    Try: SELECT TOP 10 * FROM [Transaction] ORDER BY [IDtrans] DESC

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, January 13, 2012 7:27 AM
  • User231953124 posted

    hmm thanks it works, just the last record is on the top, not on the bottom, but this isn´t big problem..

    Friday, January 13, 2012 7:38 AM
  • User-1360095595 posted

    Try: SELECT * FROM [Transaction] WHERE IDtrans IN (SELECT TOP 10 IDtrans FROM [Transaction] ORDER BY [IDtrans] DESC) ORDER BY IDtrans

    Friday, January 13, 2012 7:54 AM