[Transfer] mysql query the top n

2010-08-19  来源:本站原创  分类:Database  人气:34 

We know that in ms sql server or access, the
To check the first 10 records, you can use the top 10,
But in mysql does not support this provision, it uses limit 10.

We can support the use of MySQL in a SELECT clause - LIMIT - to accomplish this function.
LIMIT can achieve top N queries, you can achieve the M to N (a period) of the records check, the specific syntax is as follows:
SELECT * FROM MYTABLE
ORDER BY AFIELD
LIMIT offset, recnum
Offset from the first few of them (M +1) records began, recnum for the number of records returned. Example:
select * from mytable
order by afield
limit 2, 5
That means starting from the first 3 records of 5 records.

相关文章
  • [Transfer] mysql query the top n 2010-08-19

    We know that in ms sql server or access, the To check the first 10 records, you can use the top 10, But in mysql does not support this provision, it uses limit 10. We can support the use of MySQL in a SELECT clause - LIMIT - to accomplish this functi

  • (Transfer) MySQL Query Cache description and application questions 2010-09-25

    Of the article: Sky.Jian Original link: MySQL Query Cache Summary As the name suggests, MySQL Query Cache is used to cache and Query-related data. In particular, Query Cache cache our client submitted to the MySQL's SELECT statement and the statement

  • Transfer: MYSQL query cache 2010-10-23

    MySQL query cache Starting from MySQL 4.0.1, MySQL server has one important feature: Query Cache. When in use, the query cache stores the text of a SELECT query sent to the client with the corresponding results. If, after a similar query is received,

  • [Transfer] MYSQL query time range 2011-09-09

    For each type has a range of values ​​and a specified date and time value of any valid format is described in 7.3.6 the date and time types. Here is an example of using the date function. The following query selects all records, the value of its date

  • (Transfer) mysql in the query cache 2010-07-12

    As the name suggests, MySQL Query Cache is used to cache and Query-related data. Specifically, Query Cache cache our client submitted to MySQL's SELECT statement and the statement of the result set. Roughly speaking, is to SELECT statements and state

  • mysql query optimization index 2010-09-21

    Reproduced: http://hi.baidu.com/wenzi_momo/blog/item/4ee4aeeac34d4a242cf53470.html First, the data type of optimization. 1, so that your data is as small as possible one of the most basic optimization is to make your data (and indexes) on disk (and i

  • (Transfer) mysql memory usage summary in 2010-07-13

    mysql memory management is more complicated, Summary, the fall into two categories: A thread exclusive global shared memory Memory 2 Said first thread exclusive memory: Thread stack information using memory (thread_stack): mainly used to store each t

  • [Transfer] mysql sql joint index with the index 2010-11-29

    Transfer from: http://hi.baidu.com/lssbing/blog/item/b4fa993bc4876ee615cecbc5.html Note: Index (Name, Age) that the Name, Age two indexes on the establishment of a joint Because the database query performance index has a critical influence, here are

  • Database skills - MySQL Optimization Tips Top Ten 2011-07-17

    Author of Blue Jay WEB developers not only to solve the program's efficiency, quick access to the database and the corresponding is also a big problem. We hope this can help to master the skills to optimize MySQL. 1. Optimize your MySQL query cache Q

  • [Transfer] MySQL performance optimization experience the best of 20 + 2010-12-03

    Transfer: http://coolshell.cn/articles/1846.html Today, the operation of the database application performance is increasingly becoming the bottleneck, and this is particularly evident for Web applications. On database performance, this is not just DB

  • [Transfer] MySQL index 2011-08-15

    Transfer: http://database.51cto.com/art/200910/156685.htm Index is the key to quick search. MySQL MySQL index established for the efficient operation is very important. Here are some common types of MySQL indexes. In a database table, the field index

  • mysql query duplicate field 2010-03-19

    mysql query duplicate field July 11, 2007 | Posted by admin There is a big table in the database, need to find the name of which there are duplicate records id, for comparison purposes. If only to find the database name does not duplicate the field,

  • Mysql query optimizer of 2010-03-30

    1 Definition Mysql query optimizer's job is to select the appropriate query execution path. Query Optimizer code is generally constant changes, which are not the same, and storage engine. Therefore, the need to understand the latest version of the qu

  • On the mysql query cache 2010-02-12

    As the site traffic grew rapidly, increasing pressure on database queries, think of the mysql query optimization. Look for some information, when there are additions or deletions to change when, mysql query cache will automatically update the cache,

  • MYSQL query alias specified 2010-08-16

    Error: Column 'create_user' in where clause is ambiguous Reason: [transferred from: http://blog.sina.com.cn/s/blog_54fde7ac0100ej9v.html?retcode=0] At a time when using the mysql database query error occurred Column 'languageid' in where clause is am

  • mysql query not case-sensitive in solution 2010-08-28

    For the mysql query is not case sensitive issue when there are two solutions 1, modify the database table field properties A. When you create the table set up: if CREATE TABLE `account` ( `ACCT_CODE` varchar(300) binary NOT NULL, ...... ) B. create t

  • MySQL query cache code examples the practical application of 2010-10-09

    The following article focuses on the practical application of MySql query cache code, and view the MySQL query cache size, defrag, clear cache and monitor the performance of MySQL query cache is a description of relevant content, the following is a d

  • Transfer: Mysql case sensitive issue 2010-10-11

    A, 1 CREATE TABLE NAME (name VARCHAR (10)); On the table, by default, following the results of two queries is the same: SELECT * FROM TABLE NAME WHERE name = 'clip'; SELECT * FROM TABLE NAME WHERE name = 'Clip'; MySql query is not case sensitive by d

  • MySQL Query Profile is simple to use [Reserved] 2010-12-13

    Simple to use MySQL Query Profile MySQL Query Profile MySQL 5.0.37 or above began to support MySQL Query Profiler, you can check how much time will execute this SQL and see the CPU / Memory usage during the execution of System lock, Table lock how mu

  • real or.in mysql query efficiency with union all 2011-01-13

    OR, in and union all query efficiency which in the end fast. Many voices are saying online union all faster than or, in, as or, in will lead to full table scans, they give a lot of instances. But the union all really really faster than or, in? This a