redbishop — 2013-11-26T04:43:12-05:00 — #1
I'm fetching some data from a MySQL database. One of my columns “prices_from” includes the prices of the products I'm displaying. The type is decimal(6,2). How can I sort the query results according to lowest or highest price? I have heard of the MIN() and MAX() functions but how do I use these in the WHERE part of the query?
WHERE car=”BMW” && prices_from=......?
Thank you for your help.
john_betong — 2013-11-26T05:34:58-05:00 — #2
Try appending "ORDER BY prices_from;" to your SQL statement.
redbishop — 2013-11-26T07:51:05-05:00 — #3
Hi there John,
thanks for the info. Will try it out.
sama74 — 2013-11-28T11:22:45-05:00 — #4
By default the list will be in ascending order, so lowest first. To reverse this to highest first or descending, add "DESC" to the end of the query after the column name.
SELECT * FROM tablename ORDER BY prices_from DESC
redbishop — 2013-12-19T05:24:01-05:00 — #5