General Question
MySQL order by primary key, put one row on top.
Hi Flutherites!
I have a table in my MySQL database. Imagine just a standard table: id, val, plus one column named `active`, which is an ENUM(‘active’,‘not_active’).
There is either one or no record with `active` set to ‘active’. I want to sort my table using a query, so that the order is just standard (ORDER BY id ASC
), but it puts the record with `active`=‘active’ on top, if available.
I’m using CodeIgniter if that helps anyone. My current query code is:
$query = $this->db->query(“SELECT * FROM presets”);
Maybe rearrange the $query
-array instead of using a query if it can’t be done? I hope someone knows, otherwise I’ll have to write some workaround.
Thanks!
Davey.
3 Answers
Answer this question
This question is in the General Section. Responses must be helpful and on-topic.