Skip to content
Advertisement

How can I select the second last and last row from the database?

When we are retrieving data from database, we use something like this

SELECT * FROM Names

However, we will get all the data inside the specific table. Since I am going to update some data to the database and want to make a comparison bewteen the last row of data in the db and the most updated data, how can I select and retrieve the last two row of the database only?

Advertisement

Answer

If you were using SQL Server, you would do something like this:

SELECT TOP 2 * FROM Names ORDER BY Name DESC
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement