Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Select MAX(value) in ORM
  • Is it possible to use the DB::expr() method for the SELECT section of the ORM query and get the COUNT() or MAX() of a certain column?

    Code:
    $history = History::find('all', array(
       'select' => DB::expr('MAX(value)'),
       'limit' => 100
    ));

    Error: 
    Fuel\Core\Database_Exception [ Error ]: SQLSTATE[42S22]: Column not found: 1054 Unknown column 't0.MAX(value)' in 'field list' with query: "SELECT `t0`.`MAX(value)` AS `t0_c0`, `t0`.`id` AS `t0_c1` FROM `history` AS `t0` LIMIT 100"

    I was hoping to accomplished the same result as this: http://fuelphp.com/forums/discussion/2867/mysql-functions

    Thanks!

  • HarroHarro
    Accepted Answer
    No, at the moment it is not, and it's not possible to implement it without quite a rewrite.

    Why not use:

    $max = History::max();

    instead?

    Or

    $max = History::query()->limit(100)->max();

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion