clear markdown compare help best fiddles feedback
clear markdown donate comments/suggestions/bugs a leap of faith? bible365 diddy dollings
By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0. 2805438 fiddles created (40832 in the last week).

CREATE TABLE table1 ( `id` INTEGER, `title` VARCHAR(18), `rank_index` VARCHAR(4) ); INSERT INTO table1 (`id`, `title`, `rank_index`) VALUES ('1', 'An awesome product', NULL), ('2', 'Another product', '3'), ('3', 'Baby car', NULL), ('4', 'Green carpet', '1'), ('5', 'Toy', NULL);
 hidden batch(es)

SELECT, t1.`title`,t1.`rank_index` FROM table1 t1 CROSS JOIN ( SELECT MAX(id) maxid FROM table1) t2 ORDER BY IF(rank_index IS NULL, maxid - id + 1 , rank_index - 0.5) ASC
id title rank_index
4 Green carpet 1
5 Toy
2 Another product 3
3 Baby car
1 An awesome product
 hidden batch(es)