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
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 Go to previous message
Barbara Boehmer
Messages: 8635
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.
Previous Topic: Query to extract information based on random search separated by commas
Next Topic: SQL Request...
Goto Forum:
  


Current Time: Thu Dec 08 14:33:55 CST 2016

Total time taken to generate the page: 0.10944 seconds