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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.