Mysql LIMIT 不限制我的查询

Mysql LIMIT not limiting my query

为什么下面的查询 return 记录从 32 - 54 而不是在 LIMIT 子句中指定?

SELECT
    info.*,
    type.titulo AS type_name,
    category.titulo AS category_name
FROM infos_infos info
LEFT JOIN infos_categories category
    ON category.id=info.category
LEFT JOIN infos_canais type
   ON type.id=info.type
WHERE
    info.active=1 AND
    type.active=1
GROUP BY info.id
LIMIT 32,48 

From the docs 它说:

The LIMIT clause can be used to constrain the number of rows returned by the SELECT statement.

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. The offset of the initial row is 0 (not 1):

所以你想要什么所以设置LIMIT喜欢

LIMIT 32, 16 # this will return rows from 32 - 48

回答你的问题"Why the following query return records from 32 - 54?"这是因为你设置的开始是32,而你没有超过54个项目。这就是为什么。 LIMIT 32,48 将尝试显示 32 - 80 行!

SQL 应该是:

SELECT
        info.*,
        type.titulo AS type_name,
        category.titulo AS category_name
    FROM infos_infos info
    LEFT JOIN infos_categories category
        ON category.id=info.category
    LEFT JOIN infos_canais type
       ON type.id=info.type
    WHERE
        info.active=1 AND
        type.active=1
    GROUP BY info.id
    LIMIT 32,16

https://dev.mysql.com/doc/refman/5.7/en/select.html

你使用的 LIMIT 是一个 OFFSET + Count ,你可能有不到 80 (32+48) 个结果,所以它显示你从偏移量 32 到你的数据结束

SELECT * FROM tbl LIMIT 5,10;  # Retrieve rows 6-15