Find Last value Record From a Table?
Select top 1 from YourTableName order by YourIdColumn desc
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:
SELECT TOP 1 * FROM my_table ORDER BY created_at DESC;
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:
SELECT TOP 1 * FROM my_table ORDER BY id DESC;