MySQL sort by 0 and then from smallest to largest in medoo

108 Views Asked by At

I am trying to do a mysql sort that displays 0 first and then by the smallest number.

$query = "SELECT DISTINCT id FROM `items` WHERE `name`='Mag' AND `var`='Bl' ORDER BY atrow + 0 ASC"

How to write it in medoo?

$item = $database->select("items", "@id", [
    "var[=]" => "Bl",
    "name[=]" => "Mag",
    "ORDER" => ["atrow" => "ASC"]
]);

This is not working properly.

1

There are 1 best solutions below

4
On

You need a two tiered sort here. Assuming we use the following raw MySQL query:

SELECT DISTINCT id
FROM item
ORDER BY row != 0, row;

PHP code:

$item= $database->select("items", "@id", [ "ORDER" => Medoo::raw("`row` != 0, `row`")]);