Home » SQL & PL/SQL » SQL & PL/SQL » Last 6 values
Last 6 values [message #204506] Tue, 21 November 2006 01:06 Go to next message
Messages: 122
Registered: February 2006
Senior Member
How can I view the last 6 values in my table.
For example in the employees table I am always inserting new values. I want to see who are the 6 employees who have joined recently. How can I do this?
Re: Last 6 values [message #204507 is a reply to message #204506] Tue, 21 November 2006 01:21 Go to previous message
Barbara Boehmer
Messages: 8727
Registered: November 2002
Location: California, USA
Senior Member
You would need to have a column with the date joined or a sequentially assigned id or some such thing that you can order by. If you order by that in descending order in a subquery, then you can select the top 6 rownums from an outer query, something like:

(SELECT * FROM employees ORDER BY join_date DESC)

It is important to understand that Oracle does not necssarily store or retrieve data in the order that it was entered. To guarantee order, you must have a colum that you can order by. Even rowid is not reliable for this.
Previous Topic: Query to extract information based on random search separated by commas
Next Topic: SQL Request...
Goto Forum:

Current Time: Thu Jul 27 13:53:08 CDT 2017

Total time taken to generate the page: 0.15035 seconds