Suppose I have table A with its active entry in yii2. What is the best way to load the record with the maximum date created into the model.
This is the request:
select * from A where created_date = ( select max(created_date) from A )
Now I get the maximum date first, and then use it in another access to the database, i.e.:
$max = A::find()->select("created_date)")->max(); $model = A::find()->where("created_date = :date",[":date"=>$max])->one();
I am sure that this can be done with a single access to the database, but I do not know how to do it.
please help.
source share