Jump to content

[SOLVED] ORDER BY formula


abdfahim

Recommended Posts

well, if i use ORDER BY key1,key2, then it will order the result first by key1, then by key2. But i want to order it by the result of key1 multiply key2. So, i was asking is there any other way other than including another column which will store key1 multiply key2 and then order by that column?

Link to comment
Share on other sites

guys guys ... i think we are going away from the objective [:)] ........... my question was, like I have a table

Person   columnA   columnB

A             10          55
B              8           61
C             15          35

 

Now I want to arrange the table with the Person with highest (columnA multiply columnB) at the top, and so ... Is it possible without adding another column?

 

Link to comment
Share on other sites

Okay, sorry... back to the topic:

 

 

Here is what you (probably) need:

 

SELECT `theFieldINeed`, `fieldOne`*`fieldTwo` as orderby FROM `table` ORDER BY orderby

 

 

Explanation: theFieldINeed is the result what I want.

With 'fieldOne'*'fieldTwo' i combine (multiple) the two fields I want to order by and defin them as orderby (you can call it whatever you want)

From 'table' is clear and you order by oderby (in my case or the word you choose)

 

 

Give it a try

Link to comment
Share on other sites

so if I put 'ORDER BY 135', what would happen?

Well you can order by 135... but the result will be the same than like without  :P

Actually, it will order by the 135th column in the select list; 135 wasn't quoted in your example.

 

 

Is it possible in SQL to run query ORDER BY formula, for example .......... ORDER BY (ColumnA * ColumnB) ?

Did you actually try this?  It will work.

 

Link to comment
Share on other sites

thankx vamosbenedikt ... i got it ...

 

thanx ... fenway .. the thing is I tried that but it didn't work b4 ... but after getting ur post, I again tried and it works !!!! I must have done something else wrong.

 

Sorry for the inconvenience and appreciate ur help.

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.