Hi! Could we please enable some services and cookies to improve your experience and our website?
Online Sandbox for SQL and PHP: Write, Run, Test, and Share SQL Queries and PHP Code
CREATE TABLE countries (
id int,
name varchar(100)
);
INSERT INTO countries (id, name)
VALUES
(1, 'Albania'),
(2, 'Bahamas'),
(3, 'Canada'),
(4, 'United States'),
(5, 'United Kingdom'),
(6, 'Ireland'),
(7, 'Algeria');
<?php
var_export(
$db->table('countries')
->orderByRaw("FIELD(name, 'Canada', 'United Kingdom', 'United States') DESC")
->orderBy('name', 'ASC')
->get()
->toArray()
);