Get max value in a database field

For Joomla! 2.5 Coding related discussions, please use: http://groups.google.com/group/joomla-dev-general
Note: All 1.6, 1.7 and 3.5 releases have reached end of life and should be updated to 3.x.

Moderator: ooffick

Forum rules
Please use the mailing list here: http://groups.google.com/group/joomla-dev-general rather than this forum.
Post Reply
willcycle
Joomla! Apprentice
Joomla! Apprentice
Posts: 10
Joined: Fri Apr 23, 2010 12:23 pm

Get max value in a database field

Post by willcycle » Wed Mar 16, 2016 9:28 pm

How would I get the maximum value of a particular field in a Joomla database? I have an 'assetid' database column that is not automatically incremented and I would like to use Joomla Query to find the highest value in the table.

User avatar
sudo-web
Joomla! Ace
Joomla! Ace
Posts: 1325
Joined: Fri Jan 22, 2016 7:10 pm
Location: Vienna - Austria
Contact:

Re: Get max value in a database field

Post by sudo-web » Wed Mar 16, 2016 9:38 pm

I assume you have some coding knowledge if you ask that question.
The best way is to use the Joomla Methods for that:

https://docs.joomla.org/Selecting_data_using_JDatabase

Code: Select all

$query
    ->select('MAX('.$db->quoteName('assetid').')')
    ->from($db->quoteName('#__table'));
If you need help with it just ask.
Visit me on my Webdesign Webpage: https://www.posit.at

willcycle
Joomla! Apprentice
Joomla! Apprentice
Posts: 10
Joined: Fri Apr 23, 2010 12:23 pm

Re: Get max value in a database field

Post by willcycle » Thu Mar 17, 2016 8:08 pm

Thanks. Works fine


Post Reply

Return to “Joomla! 2.5 Coding”