Q
Problem solve Get help with specific problems with your technologies, process and projects.

Retrieving the second row inserted

How do I retrieve a partuclar row from a table? For example, I want to retrieve only the second row inserted into the destination table. Is it possible through the use of row IDs?

Your answer all depends on what you mean as the "second row" of the table. Let's assume I insert four rows into my table as denoted by:

1
2
3
4
I then delete row "2". The table rows will look like:
1

3
4
Which is the second row here? Is it the NULL row or the "3"?

Now assume that I insert the value "5". The table rows might look like:

1
5
3
4
What is the second row here? Is it the "5", or is it the "3" which is the second "oldest" row in the table?

If you are looking for the second row, as stored in physical sort order, then a query similar to the following might help you out:

SELECT x.ename
FROM (SELECT ename,rownum AS rowno FROM emp) x
WHERE x.rowno=2;
If you are looking for the second oldest row, then you will need to come up with some other way to sort your data by time and bring out just the second oldest row.

For More Information


Dig Deeper on Oracle database design and architecture

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.

-ADS BY GOOGLE

SearchDataManagement

SearchBusinessAnalytics

SearchSAP

SearchSQLServer

TheServerSide.com

SearchDataCenter

SearchContentManagement

SearchHRSoftware

Close