Skip to content
Advertisement

How to get the last row of an Oracle a table

I want to get the last row, which I inserted into a table in an Oracle 11g Express database. How can I do this?

Advertisement

Answer

There is no such thing as the “last” row in a table, as an Oracle table has no concept of order.

However, assuming that you wanted to find the last inserted primary key and that this primary key is an incrementing number, you could do something like this:

If you have the date that each row was created this would become, if the column is named created:

Alternatively, you can use an aggregate query, for example:

Here’s a little SQL Fiddle to demonstrate.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement