Umer Singhera
Umer Singhera

Reputation: 95

Show records ordered with maximum price first in PHP & MySQL

I store bike name and their prices. Now I want show all my bikes ordered with maximum price (most expensive) first, as in:

bike 800 cc     1600$
bike 400 cc     800$
bike 200 cc     400$
bike 100 cc     200$

Upvotes: 2

Views: 280

Answers (2)

user319198
user319198

Reputation:

SELECT * FROM bikes ORDER BY price DESC

check if datatype of price column is varchar then it will not work properly. So use below trick:

 SELECT * FROM bikes ORDER BY price+0 desc

This is a quick fix instead of sorting to CAST operator.

Upvotes: 3

Sergio Tulentsev
Sergio Tulentsev

Reputation: 230336

SELECT * 
FROM bikes
ORDER BY price DESC

Upvotes: 2

Related Questions