Sort by Specific Field-Values in a Field in MySql / MariaDB

Use the following example to sort by specific field-values in your table

...
ORDER BY FIELD('field_name', 'value_or_array') DESC,
​another_field_name
...

 

In CakePHP 4, you can start with the following example:

$order = [ 'FIELD(year_field_name, ' . date('Y') . ') DESC', 'another_field' ];

Share this Post