Mysql order by: to skip zeros to end of list
mysql, php, sql-order-by, zero
Solution
Try this:
$query = "
SELECT products.*, login1.*
FROM products
LEFT JOIN login1 ON products.id_user = login1.id_user
WHERE products.product LIKE '" . $search_keyword . "'
ORDER BY IF(products.rate = 0, 1, 0), products.product, products.rate "
This adds an initial check to the sort order so that products with a rate of `0` are listed after all products that have a rate not equal to `0`.
Problem
``` $query = "SELECT products.*, login1.* FROM products LEFT JOIN login1 ON products.id_user = login1.id_user WHERE products.product LIKE '".$search_keyword."' ORDER BY products.product, products.rate " ``` When using this query the products with rate 0 list first, But I want that to display last, with no other change in the order. How can I achieve this.