Question: I want to run a simple query to get the "n" oldest records in the table. (It has a creation\_date column).

How can i get that without using "order-by". It is a very big table and using order by on entire table to get only "n" records is not so convincing.

(Assume n << size of table)

Answer: 
When you are concerned about performance, you should probably not discard the use of order by too early.

Queries like that can be implemende as Top-N query supported by an appropriate index, that's running very fast because it doesn't need to sort the entire table, not even the selecte rows, because the data is already sorted in the index.

example:

```
select *
  from table
 where A = ?
 order by creation_date 
 limit 10;

```

without appropriate index it will be slow if you are having lot's of data. However, if you create an index like that:

```
create index test on table (A, creation_date );

```

The query will be able to start fetching the rows in the correct order, without sorting, and stop when the limit is reached.

**Recipe**: put the where columns in the index, followed by the order by columns.

If there is no where clause, just put the order by into the index. The order by must match the index definition, especially if there are mixed asc/desc orders.

The indexed Top-N query is the performance king--make sure to use them.

I few links for further reading (all mine):

[How to use index efficienty in mysql query](https://stackoverflow.com/questions/3778319/how-to-use-index-efficienty-in-mysql-query/3778542#3778542)

<http://blog.fatalmind.com/2010/07/30/analytic-top-n-queries/> (Oracle centric)

<http://Use-The-Index-Luke.com/> (not yet covering Top-N queries, but that's to come in 2011).
Create an index on `creation_date` and query by using `order by creation_date asc|desc limit n` and the response will be very fast (in fact it cannot be faster). For the "latest n" scenario you need to use `desc`.

If you want more constraints on this query (e.g `where state='LIVE'`) then the query may become very slow and you'll need to reconsider the indexing strategy.