tags:

views:

63

answers:

4

Hi,

I want to know the alternative of the TOP keyword as in mysql.

I have read about Top Keyword in SQL.

Is there any alternative for that in MYSQL.

Or any other method in mysql from which we can get same functionality.

Thanks

Avinash

+2  A: 

Ordering and limiting the results:

SELECT field1, field2
FROM myTable
ORDER BY field1 ASC
LIMIT 10
Jonathan Sampson
A: 

yes, there is the limit clause.

Example:

    SELECT * FROM `your_table` LIMIT 0, 10 

This will display the first 10 results from the database.

Sarfraz
@Pascal: praising him, i like his comprehensive answers and he is also fast, not you man, you see i put my comment in pascal's answer :)
Sarfraz
A: 

You can use the LIMIT keyword (See the documentation of the SELECT instruction) -- it goes at the end of the query :

select *
from your_table
where ...
limit 10

to get the top 10 lines


Or even :

select *
from your_table
where ...
limit 5, 10

To get 10 lines, startig from the 6th (i.e. getting lines 6 to 15).

Pascal MARTIN
Will it manipulate all data of the table...??
Avinash
This man is always so cool and fast with his answers, great stuff man :)
Sarfraz
@Avinash : I'm not sure I can give a definite answer that will be true for every situation, but, in some case, it will manipulate more data that you'd like *(for instance, when there is an `order by` clause, the `limit` can only be applied after the `order by` has been calculated, obviously)* ;;; @Sarfraz : thanks ;-)
Pascal MARTIN
let me explain my actual problem.My problem is that i have table with 9lac record.i just want to measure the time query execution time on my web page.So i have decided to display only some records on page but query should manipulate all record. so how could i do it.????
Avinash
A: 

mysql equivalent of top and you can find further more about LIMIT in MySql Doc

Sri Kumar