Jump to content

Recommended Posts

Erhhmm..

 

We need column names to give you a proper query. You have only given us the table name.

 

$sql = "SELECT * FROM names ORDER BY name ASC LIMIT 5";

 

Note replace the "name" column with the column you want to do the alphabetical sorting with.

Well actually when I originally made that post I had read it thinking you put date before name, and so I had a post about that.  Then I edited it and didn't know what else to say...so...yea.

 

But anyway, by putting ORDER BY name ASC, date DESC, it won't even look at the date to order by unless two people with the same name come up.  If there are no two people with the same name, then it won't order by the date.

Well actually when I originally made that post I had read it thinking you put date before name, and so I had a post about that.  Then I edited it and didn't know what else to say...so...yea.

 

But anyway, by putting ORDER BY name ASC, date DESC, it won't even look at the date to order by unless two people with the same name come up.  If there are no two people with the same name, then it won't order by the date.

 

i was not aware of that. good to know. thanks for the tip bro!

Yea, the second ORDER BY in the clause is a fallback.  Basically, this

 

NAME                DATE

  Mark                345323

  Andrew            204284

  Mark                134533

 

Will become:

NAME                DATE

  Andrew            204284

  Mark                134533

  Mark                345323

 

There's no other way to really use another column to "sort" data, unless you're going to use it as a fallback.  Nothing else really makes sense.

wait, i already knew that! =) for some reason i was thinking about it differently than you explained it, but i'm on the same page. the second ORDER BY clause won't take effect unless there are more than one of the same field values for the first ORDER BY clause. that makes total sense.

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.