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

Latest entry with single select statement

I have a table, emp, and two fields, empid and empname. The column empid has a primary key. How do I get the latest entry into the empname column with a single select statement?

I have a table, emp, and two fields, empid and empname. The column empid has a primary key. My question is, how do I get the latest entry into the empname column with a single select statement?
I'm not sure what you mean by "latest entry." To me, this implies that you are looking for the last inserted row of data. If the EMPID column is an increasing sequence, then this would be as easy as finding the row with the largest EMPID value and then finding the other column values based on the largest EMPID. The following query does just that:
SELECT empid,empname FROM emp 
WHERE empid IN (SELECT MAX(empid) FROM emp);

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