开发者

Is there an alternative to TOP in MySQL?

开发者 https://www.devze.com 2022-12-20 10:59 出处:网络
I want to know the alternative of the TOP keyword as in MySQL. I have read about TOP in SQL Server. Is there any alternative to this in MySQL, or any other method in MySQL from which we can get same

I want to know the alternative of the TOP keyword as in MySQL. I have read about TOP in SQL Server.

Is there any alternative to this in MySQL, or any other method in MySQL from which we can get same fun开发者_JS百科ctionality?


Ordering and limiting the results:

SELECT field1, field2
FROM myTable
ORDER BY field1 ASC
LIMIT 10


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).


yes, there is the limit clause.

Example:

    SELECT * FROM `your_table` LIMIT 0, 10 

This will display the first 10 results from the database.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号