Search code examples
mysqlsql-order-by

Why is this Mysql Descending query not returning as intended?


i have this query:

SELECT product_list.id AS listId, product.prod_name AS prodName, FORMAT(MIN(pricelist.price),0) AS price 
FROM product_list 
INNER JOIN product ON product_list.id = product.prod_list_id 
INNER JOIN pricelist ON product.id = pricelist.prod_id 
WHERE product_list.id='2' 
GROUP BY listId, prodName 
ORDER BY price DESC

i want to make the price descending. can you tell me why this query return this: query result


Solution

  • The FORMAT function returns a string so you are not ordering based on integer values. You can use the inner call of that function to order and it will be by the integer value.

    order by MIN(pricelist.price) desc