Mysql限制功能似乎对我不起作用

时间:2010-05-24 07:33:34

标签: mysql function limit

这是我的查询,

select t1.dSyllabus_id,t1.dBatch,t1.dFilePathName,
t2.dDegreeName,t3.dDepartmentAbbr
from tbl_syllabus as t1
join tbl_degree_master as t2,
tbl_department_master as t3
where t2.dDegree_id=t1.dDegree_id 
and t3.dDepartment_id=t1.dDepartment_id
and t1.dCollege_id='1'
and t1.dIsDelete='0'

我得到了

Without Limit http://img534.imageshack.us/img534/2165/withoutlimi.jpg

申请限额,

 select t1.dSyllabus_id,t1.dBatch,t1.dFilePathName,
    t2.dDegreeName,t3.dDepartmentAbbr
    from tbl_syllabus as t1
    join tbl_degree_master as t2,
    tbl_department_master as t3
    where t2.dDegree_id=t1.dDegree_id 
    and t3.dDepartment_id=t1.dDepartment_id
    and t1.dCollege_id='1'
    and t1.dIsDelete='0'
    limit 0,5

我明白了,

With Limit http://img13.imageshack.us/img13/2470/withlimit.jpg

我没有得到前五个记录的原因?

2 个答案:

答案 0 :(得分:3)

您获得5条记录,但尚未设置订单。除非你告诉他们,否则他们不会按特定顺序回来。在你的情况下,我相信你想要他们的id。添加如下内容:

order by `t1`.`dSyllabus_id` ASC

所以你的查询看起来像是:

select t1.dSyllabus_id,t1.dBatch,t1.dFilePathName,
t2.dDegreeName,t3.dDepartmentAbbr
from tbl_syllabus as t1
join tbl_degree_master as t2,
tbl_department_master as t3
where t2.dDegree_id=t1.dDegree_id 
and t3.dDepartment_id=t1.dDepartment_id
and t1.dCollege_id='1'
and t1.dIsDelete='0'
order by `t1`.`dSyllabus_id` ASC
limit 0,5

答案 1 :(得分:2)

使用ORDER BY

and t1.dIsDelete='0'
    ORDER BY 't1.dSyllabus_id'
    limit 0,5