Joomla Database - How to use LIMIT in getQuery?(Joomla 数据库 - 如何在 getQuery 中使用 LIMIT?)
问题描述
我想使用 joomla 内置数据库类构建以下查询.
I want to build the below query using joomla inbuilt database class.
SELECT *
FROM table_name
ORDER BY id DESC
LIMIT 1
这是我目前建立的查询.
This is the query I have built up to now.
$db =& JFactory::getDBO();
$query = $db->getQuery(true);
$query->select($db->nameQuote('*'));
$query->from($db->nameQuote(TABLE_PREFIX.'table_name'));
$db->setQuery($query);
$rows = $db->loadObjectList();
我不知道如何将限制(LIMIT 1)添加到查询中.有人可以告诉我怎么做吗?谢谢
I don't know how to add the limit(LIMIT 1) to the query. Can someone please tell me how to do it? Thanks
推荐答案
早于 Joomla 3.0
$db = JFactory::getDBO();
$query = $db->getQuery(true);
$query->select('*')
->from($db->nameQuote('#__table_name'))
->order($db->nameQuote('id').' desc');
$db->setQuery($query,0,1);
$rows = $db->loadObjectList();
$db->setQuery
函数接受 3 个参数.第一个是查询,然后是开始,然后是限制.我们可以限制记录,如上所示.
$db->setQuery
function takes 3 parameters. The first one being the query, then the start, then the limit. We can limit records as shown above.
setLimit(integer $limit, integer $offset)
如果你只想要一行
$query->setLimit(1);
阅读更多
这篇关于Joomla 数据库 - 如何在 getQuery 中使用 LIMIT?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Joomla 数据库 - 如何在 getQuery 中使用 LIMIT?


基础教程推荐
- 带有WHERE子句的LAG()函数 2022-01-01
- MySQL 5.7参照时间戳生成日期列 2022-01-01
- ORA-01830:日期格式图片在转换整个输入字符串之前结束/选择日期查询的总和 2021-01-01
- MySQL根据从其他列分组的值,对两列之间的值进行求和 2022-01-01
- 带更新的 sqlite CTE 2022-01-01
- while 在触发器内循环以遍历 sql 中表的所有列 2022-01-01
- CHECKSUM 和 CHECKSUM_AGG:算法是什么? 2021-01-01
- 从字符串 TSQL 中获取数字 2021-01-01
- 使用 VBS 和注册表来确定安装了哪个版本和 32 位 2021-01-01
- 如何在 CakePHP 3 中实现 INSERT ON DUPLICATE KEY UPDATE aka upsert? 2021-01-01