简体   繁体   English

如何设置2选择查询的LIMIT?

[英]How to set the LIMIT of 2 select query?

can you give a sample to how can i set the limit of my join query.. i used that code for pagination.. 您能举一个例子说明我如何设置我的联接查询的限制吗。我用该代码进行分页。

select a.last_name, a.first_name, a.middle_name, a.school_year,
a.student_no,a.year_level,DATE_FORMAT(date_register,'%M %d %Y/%r')date_register 
from dbo_student a 
inner join tbl_student_lc b on a.student_no = b.student_no 
order by a.last_name ASC;

Try this : 尝试这个 :

SELECT a.last_name, a.first_name, a.middle_name, a.school_year,
a.student_no,a.year_level,DATE_FORMAT(date_register,'%M %d %Y/%r')date_register 
FROM dbo_student a 
INNER JOIN tbl_student_lc b ON a.student_no = b.student_no 
ORDER BY a.last_name ASC LIMIT 0, 2;

The LIMIT clause can be used to constrain the number of rows returned by the SELECT statement. LIMIT子句可用于约束SELECT语句返回的行数。 LIMIT takes one or two numeric arguments, which must both be nonnegative integer constants (except when using prepared statements). LIMIT接受一个或两个数字参数,这两个参数都必须是非负整数常量(使用预处理语句时除外)。

With two arguments , the first argument specifies the offset of the first row to return, and the second specifies the maximum number of rows to return. With two arguments ,第一个参数指定要返回的第一行的偏移量,第二个参数指定要返回的最大行数。 The offset of the initial row is 0 (not 1): 初始行的偏移量为0(不是1):

Refer: http://dev.mysql.com/doc/refman/5.0/en/select.html 参考: http : //dev.mysql.com/doc/refman/5.0/en/select.html

SELECT * FROM `your_table` LIMIT 0, 10 

这将显示数据库的前10个结果。

要添加限制,您可以尝试在查询结束时添加ORDER BY a.last_name ASC LIMIT 0,2

Simple add LIMIT 0,2 at the last of your query like 只需在查询的最后添加LIMIT 0,2,例如

ORDER BY a.last_name ASC LIMIT 0,2   //OR LIMIT 2

This will display first 2 records(rows) from your DB 这将显示数据库中的前2条记录(行)

select a.last_name, a.first_name, a.middle_name, a.school_year,
a.student_no,a.year_level,DATE_FORMAT(date_register,'%M %d %Y/%r')date_register 
from dbo_student a 
inner join tbl_student_lc b on a.student_no = b.student_no 
order by a.last_name ASC  LIMIT 0,2;

try this 尝试这个

select * from ( select a.last_name, a.first_name, a.middle_name, a.school_year,
a.student_no,a.year_level,DATE_FORMAT(date_register,'%M %d %Y/%r')date_register 
from dbo_student a 
inner join tbl_student_lc b on a.student_no = b.student_no 
order by a.last_name ASC) as t1 limit 0,2 ;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM