SQL to return the rownum of a specific row? (using Oracle db)

Posted by jedierikb on Stack Overflow See other posts from Stack Overflow or by jedierikb
Published on 2009-02-10T21:10:14Z Indexed on 2010/05/07 17:18 UTC
Read the original article Hit count: 202

Filed under:
|
|
|

In Oracle 10g, I have this SQL:

select dog.id as dogId from CANINES dog order by dog.codename asc

which returns:

id
--
204
203
206
923

I want to extend this query to determine the oracle rownum of a dog.id in this resultset.

I have tried

select rownum from 
(select dog.id as dogId from CANINES dog order by dog.codename asc) 
where dog.id=206

But this does not work out very well (it returns 1 no matter which dog.id I match on). I was expecting to get back 3.

Thanks for your help!


Notes

http://www.oracle.com/technology/oramag/oracle/06-sep/o56asktom.html

I am pretty sure I do not need to use rowid

© Stack Overflow or respective owner

Related posts about sql

Related posts about Oracle