abdfahim Posted May 29, 2008 Share Posted May 29, 2008 Is it possible in SQL to run query ORDER BY formula, for example .......... ORDER BY (ColumnA * ColumnB) ? Quote Link to comment Share on other sites More sharing options...
Xurion Posted May 29, 2008 Share Posted May 29, 2008 Your formula makes no sense. Column A multiplied by column B? Or are you using * in the context like you would in SELECT * FROM ...? You can use: SELECT * FROM t1 ORDER BY key1, key2; Quote Link to comment Share on other sites More sharing options...
abdfahim Posted May 30, 2008 Author Share Posted May 30, 2008 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? Quote Link to comment Share on other sites More sharing options...
fenway Posted May 30, 2008 Share Posted May 30, 2008 Your formula makes no sense. I disagree.... you can order by anything you want.` Quote Link to comment Share on other sites More sharing options...
Xurion Posted May 31, 2008 Share Posted May 31, 2008 so if I put 'ORDER BY 135', what would happen? Quote Link to comment Share on other sites More sharing options...
kbh43dz_u Posted May 31, 2008 Share Posted May 31, 2008 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 Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted May 31, 2008 Share Posted May 31, 2008 Did you try that, you would get a mysql syntax error if your table did not have a column named 123 Quote Link to comment Share on other sites More sharing options...
kbh43dz_u Posted May 31, 2008 Share Posted May 31, 2008 no it works without an error. don't forgett '! ...ORDER BY '135' (i had nothing like 135 in my database) Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted May 31, 2008 Share Posted May 31, 2008 ORDER BY 135, the question that was asked, is not the same as ORDER BY '135' Quote Link to comment Share on other sites More sharing options...
kbh43dz_u Posted May 31, 2008 Share Posted May 31, 2008 (i know, i told you. you can but it dosen't make sense.) Quote Link to comment Share on other sites More sharing options...
abdfahim Posted June 1, 2008 Author Share Posted June 1, 2008 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? Quote Link to comment Share on other sites More sharing options...
kbh43dz_u Posted June 1, 2008 Share Posted June 1, 2008 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 Quote Link to comment Share on other sites More sharing options...
fenway Posted June 2, 2008 Share Posted June 2, 2008 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 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. Quote Link to comment Share on other sites More sharing options...
abdfahim Posted June 4, 2008 Author Share Posted June 4, 2008 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.