Monday, October 3, 2011

SQL Top n Rows in Informix, MySQL and SQL Server

Different dialects of SQL allow you to obtain the first n rows, resulting from a query, in different ways. The following are examples in Informix, SQL Server, and MySQL. Tip: to get the last n rows, simple switch the order by clause (from ascending to descending, or vice versa).


select first 5 *
from customer;


select *
from customer
limit 5;

SQL Server

select top 5 *
from customer;

No comments:

Post a Comment