Feeds:
Posts
Comments

Archive for the ‘SQL’ Category

Today a colleague of mine was trying to pick the top row in a result set on SQLServer, and we being  Oracle Database fans could only think of ROWNUM. So here is what we found out after digging for some time.

Rownum is used in Oracle to retrieve the N-top records.

SELECT  * FROM TABLENAME
WHERE ROWNUM<2

Note: Some things to keep in mind are that the “>=” or the “>” operators wont work with ROWNUM. Also remember ROWNUM is to only pick the required row from a result set and should not be confused with the position of the record in the table.

Finally the equivalent query in SQLServer would be

SELECT TOP 1 * FROM TABLENAME

and of course is more intuitive.

Advertisements

Read Full Post »