Vote count:
0
I want to retrieve data with a simple SELECT statement and ORDER BY, but the ORDER BY should have a fallback.
That is: my records have a filed name and a field name sortkey:
CREATE TABLE company
(`id` int, `name` varchar(10), `sortkey` varchar(10))
;
INSERT INTO company
(`id`, `name`, `sortkey`)
VALUES
(1, 'Azzz', ''),
(2, 'Bzzz', ''),
(3, 'Czzz', 'Aaa')
;
I'd like to get the result from a SELECT statement:
Czzz
Azzz
Bzzz
When I have a sortkey, use it. If not, use the field name.
Peudo code: SELECT * FROM company ORDER BY name,sortkey (but prioritize the sortkey);
asked 2 mins ago
Mysql: order by with fallback
Aucun commentaire:
Enregistrer un commentaire