LoginSignup
4
0

More than 3 years have passed since last update.

Codeigniterのorder_byで、NULLのレコードをあとに取得する方法

Posted at

MySQL

  • MySQLの ORDER BY column_name ASC で、column_nameがNULLのレコードは先に取得されるが、以下のように記述することで、column_nameがNULLのレコードをあとに取得できる。
SELECT * FROM table_name ORDER BY column_name IS NULL ASC, column_name ASC;

Codeigniter

上記をPHPのCodeigniterで実現する場合の書き方は以下

$this->db->order_by('column_name IS NULL', 'ASC', FALSE);
$this->db->order_by('column_name', 'ASC');
4
0
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
4
0