• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 351
  • Last Modified:

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
0
St_Aug_Beach_Bum
Asked:
St_Aug_Beach_Bum
1 Solution
 
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 DMCommented:
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
 
vineethvpCommented:
Try the following,


ORDER BY
      LTpricetoday,
      BWpricetoday,
      LTafterrebates,      
      id DESC
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now