Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

last 5 records again

Status
Not open for further replies.

mike1955

Programmer
Jul 21, 2005
32
0
0
GB
Hi all,
I am having some grief getting a piece of SQL to work and wonder if anyone out there does anything similar.

What I want to do is pull back records from a table and use just the last five of them in a calculation.

I am calling these through an application in which SQL seems to work ok with just a few minor syntax tweaks.

The code I have is:

select * from(
select sample_number from sample where stage = 'M10'
order by sample_number desc)
where row_number <=5


I keep getting an error re too few parameters: expected 1

any help gratefully received
mike
 
Hi,
3 things:

1: That code does not expect any parameters...
2:There is no row_number column in your query ( or in Oracle).
3: What is meant by last 5 records?





[profile]

To Paraphrase:"The Help you get is proportional to the Help you give.."
 
large table - select statement calls dataset from table where data is not sequential and the value in tne table field 'stage' is M10

I have seen quite a few variations: row_num, row_number etc and some as row_number() over etc but can't find one that works

last five records are the last 5 of the set fetched back
 
Hi,
Although the row_number() over... is the preferred method, try this older style:

Code:
select * from(
select rownum rn,sample_number from sample where stage = 'M10' order by sample_number desc)
where rn < 6






[profile]

To Paraphrase:"The Help you get is proportional to the Help you give.."
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top