Jump to content

sort results


poe

Recommended Posts

i want to sort a column and show the 4 largest numbers from smallest to largest.

i know if i " ORDER BY col DESC LIMIT 4 " that will get me the highest 4 numbers. but i now want to sort these numbers from small to large

random order:
38 : 22 : 19 : 45 : 15 : 02 : 78

ORDER BY col DESC LIMIT 4:
78 : 45 : 38 : 22  [excluded 19, 15, 02]

i want to show:
22 : 38 : 45 : 78

if i make another 'ORDER BY' it gives me an error
Link to comment
https://forums.phpfreaks.com/topic/27546-sort-results/
Share on other sites

A database is very logical, if you ask a question then it will give you an answer, but if you try to ask (2) questions at once and expect (1) answer it will never work. So ask 1 (question) < enclose the first question, then give it the second question!

[code]$sql = "(SELECT id FROM table ORDER BY id DESC LIMIT 4) ORDER BY id ASC";[/code]


printf
Link to comment
https://forums.phpfreaks.com/topic/27546-sort-results/#findComment-126666
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.