Search This Blog

Tuesday, December 28, 2010

Select first n rows from oracle, MySql and MS Sql

Assume we have table customer with columns id and age. Find first n customers with youngest ages

Oracle
select * from (select * from customer order by age) where rownum < :n
Mysql
select * from customer order by age limit :n
MS Sql
select top :n * from customer order by age

No comments:

Post a Comment