Home  >  Article  >  Database  >  Character order of order by in in mysql (recommended)

Character order of order by in in mysql (recommended)

PHPz
PHPzOriginal
2017-04-03 17:42:266760browse

The following editor will bring you a detailed discussion of the character order of mysql order by in (recommended). The editor thinks it is quite good, so I will share it with you now and give it as a reference for everyone. Let’s follow the editor and take a look.

Recommended related mysql video tutorials: "mysql tutorial"

//MySQL 语句SELECT * FROM `MyTable`WHERE `id` IN (11,1,111) ORDER BY FIELD(`id`, 11,1,111);

laravel framework

$ids = array(1,17,2);
$ids_ordered = implode(',', $itemIds);
$items = static::whereIn('id', $ids)->orderByRaw(DB::raw("FIELD(id, $ids_ordered)"))->get();

The above is the detailed content of Character order of order by in in mysql (recommended). For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn