mysql order by two fields equally


I currently have a mysql query set up with the order like this:

 ORDER BY LTpricetoday, LTafterrebates ASC, id DESC LIMIT 0, 20

I have added another product line, so now I need it to order by both LTpricetoday and BWpricetoday, so the ones with the smallest price today show up first - whichever it is.

Then after that, LTafterrebates would be the secondary order, id the last.

Does that make sense?  It is possible?

Thanks,  Chris
St_Aug_Beach_BumAsked:
Who is Participating?
 
vineethvpConnect With a Mentor Commented:
Try the following,


ORDER BY
      LTpricetoday,
      BWpricetoday,
      LTafterrebates,      
      id DESC
0
 
DrDamnitCommented:
I think I understand. Can you post the actual SQL query you are using and a sample of what you have now and an sample (hand written probably) of what you want?
0
 
St_Aug_Beach_BumAuthor Commented:

Well, currently I have it like this:

"SELECT * FROM cps WHERE updated = '1262697422' AND style = 'PDA'  ORDER BY LTpricetoday, LTafterrebates ASC, id DESC LIMIT"

but I need to add BWpricetoday into the ORDER section.

So that the results will provide a combined list ordered first of all by comparing both LTpricetoday and BWpricetoday, so I might end up with this:

BW - $0
LT - $1
LT - $1
BW - $2
LT - $3
BW - $3
LT - $4
BW - $5
0
 
Vimal DMSenior Software EngineerCommented:
Hai,

1)You can use like this
  query :  ORDER BY LTpricetoday ASC, LTafterrebates DESC, id DESC LIMIT 0, 20
======================================================================
2)Even you can use the following example aslo
  query : ORDER BY 3 DESC LIMIT 0, 20
Note:
-------
3 - indicates the first three fields of the select query.


0
 
St_Aug_Beach_BumAuthor Commented:
opps, just cut off the " DESC LIMIT 0, 20" of the previous query, but doesn't affect the question, still trying to figure out how to order by both fields on an equal level.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.