Rajeev Kumar
Find Last value Record From a Table?

Find Last value Record From a Table?

By Rajeev Kumar in .NET on Jan 18 2023
  • Jignesh Kumar
    Jan, 2023 25

    1. Select top 1 from YourTableName order by YourIdColumn desc

    • 1
  • Tuhin Paul
    Apr, 2023 15

    If you want to retrieve the last record based on a different column, you can modify the ORDER BY clause accordingly. If you want to retrieve the last record based on the created_at column, you can use this query:

    1. SELECT TOP 1 * FROM my_table ORDER BY created_at DESC;

    • 0
  • Tuhin Paul
    Apr, 2023 15

    To find the last record from a table in SQL Server, you can use the TOP clause in combination with the ORDER BY clause to sort the records in descending order based on the primary key or any other column that defines the order of records in the table.

    Assuming that you have a table called my_table with a primary key column called id, you can retrieve the last record in the table like this:

    1. SELECT TOP 1 * FROM my_table ORDER BY id DESC;

    • 0


Most Popular Job Functions


MOST LIKED QUESTIONS