SQL加入限制范围

时间:2011-04-07 16:30:28

标签: mysql sql join limit

我正在尝试为我的sql join语句添加一个限制范围,所以我可以对我的记录进行分页,但是当我输入我的语句的限制范围时,我没有得到任何返回。随着限制范围的取消,一切正常。

这就是我所拥有的:

$sql= "SELECT R.id,companyName,membershipID,addressID,city,logo,descriptionShort FROM yt_Business_RegInfo R
    INNER JOIN yt_Business_Seasons S
    ON R.id = S.busID AND S.deleted = '0'
    INNER JOIN yt_Business_Address A
    ON R.addressID = A.id
    INNER JOIN yt_Business_Membership M
    ON R.membershipID = M.id AND M.approved = 1
    WHERE R.deleted = '0'
    ORDER BY R.companyName ASC LIMIT $start, $limit";

任何建议将不胜感激。感谢。

2 个答案:

答案 0 :(得分:2)

应该是:

LIMIT $start, $howMany

如果($howMany <= 0)($start > number of rows returned without LIMIT),则会得到0结果。

答案 1 :(得分:0)

回应查询:

echo $sql;

并检查进入它的$ start和$ limit的值。