【问题标题】:Why where clause is not working while using offset?为什么使用偏移量时 where 子句不起作用?
【发布时间】:2019-05-21 16:56:14
【问题描述】:

好吧,我正在制作一个有多个过滤器的网络,它们在以下查询中运行良好

SELECT * from userInventory  limit 30 offset 0

上面的查询返回预期的行数,当我在其中添加 where 子句时,它变成了

SELECT * from userInventory where item_rarity = 'IMMORTAL' limit 30 offset 0

那么 where 子句不起作用,它返回我使用的简单选择查询结果

SELECT * from userInventory limit 30 offset 0

但我需要一个查询,其中 where 和 offset 都应该正常工作,例如

SELECT * from userInventory where item_name="name" and item_rarity = 'rarity' and usedBy = "usedBy" limit 30 offset 0

注意:如果没有上面的偏移量,查询可以正常返回预期结果,如果增加偏移量,结果为空

【问题讨论】:

  • 请添加样本记录。

标签: mysql


【解决方案1】:

尝试使用排序,例如:

SELECT * from userInventory where item_name="name" and item_rarity = 'rarity' and usedBy = "usedBy" ORDER BY SOME_FIELD DESC_OR_ASC limit 30 offset 0;

【讨论】:

  • 我已经尝试过了,它运行良好,但是当我再次发送具有相同偏移量的请求时,不幸的是它再次忽略了 where 子句并返回为“SELECT * from userInventory limit 30 offset 0 " 没有 where 子句
  • @MohammadShaheryar 所以这不是 sql 问题,对吧?是php吗?
  • 我不知道出了什么问题,基本上我正在为我的网站进行分页,所有过滤器都工作正常,即使当我点击页码 1 时默认偏移量 0 工作正常所以显然偏移量必须为 0,但这次它忽略了我不知道的 where 子句
  • “Ordernation”不是一个词,而且最容易拼错的词(“ordination”)不适用。
猜你喜欢
  • 2019-07-12
  • 2023-03-21
  • 2011-11-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-11-10
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多