Last 6 values [message #204506] |
Tue, 21 November 2006 01:06  |
orafan2003
Messages: 122 Registered: February 2006
|
Senior Member |
|
|
Hi,
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  |
 |
Barbara Boehmer
Messages: 9106 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
(SELECT * FROM employees ORDER BY join_date DESC)
WHERE ROWNUM <= 6;
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.
|
|
|