I am trying to retreive the value of a specific column from a table, from the latest row (I have an a.i id column).
What query would need to be written in order to accomplish this?
So far I have…
$lots = Yii::app()->db->createCommand()
->select('MAX(id) as num_lots')
->from('my_table')
->queryRow();
i.e. take the value from the first row of a table sorted by
idin descending order.EDIT:
As for your editted code –
MAX(id) as num_lotsin theSELECTclause selects the maximum value from theidcolumn but that’s probably not what you want.In Yii you’d probably use something like this: