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!

row_number function 1

Status
Not open for further replies.

lasd

Programmer
Jan 14, 2005
48
0
0
IE
Hi
I have a bit of a problem. Below I have pasted the row_number function i am using in my code. However i want to select where RowNumber=1 in my where clause but it doesn't recognise it. could anyone help here.

ROW_NUMBER() OVER (PARTITION BY item_key ORDER BY execution_time desc)as RowNumber

this is what i tried but it won't work.
where RowNumber=1

thanks in advance for the help.

lasd
 
Column labels (i.e. RowNumber) are only used for ORDER BY purposes and re-naming output, you can not use it in the WHERE-clause.
 
Still - most DBMS have features for fetching only the first row or first set of rows of a resultset, so if that would solve your issue post in the DBMS specific forum again.



Juliane
 
Code:
select rowNumber, 
otherColumns 
from 
(select ROW_NUMBER() OVER 
(PARTITION BY item_key 
 ORDER BY execution_time desc) as RowNumber,
 otherColumns 
from ... )dt
where rowNumber = 1
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top