Joomla Database - How to use LIMIT in getQuery?
Asked 07 September, 2021
Viewed 2.4K times
  • 73
Votes

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();

I don't know how to add the limit(LIMIT 1) to the query. Can someone please tell me how to do it? Thanks

5 Answer