0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

FuelPHPでSQLの最新のレコードを取得する

Posted at

SQLにあるレコードの、created_atが最も新しいものを取得したいといったとき、
SELECTにMAX(created_at)とするだけでやってくれます。

FuelPHPの場合は

example.php
$query = \DB::select('id', \DB::expr('MAX(created_at)'))
->from('table_name')
->execute();

とするだけでできます。
これに加えて
group_by('id')
などを使うときにすごく役立ちます。

配列で取得したあとに頑張って新しい配列に入れるみたいなことをせずに済みます。(自戒)

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?