asmith Posted June 30, 2008 Share Posted June 30, 2008 hi table test id num1 num2 num3 1 23 21 34 2 34 32 3 . . . is it possible to achive this : select id from test where num1+num2+num3 is maximum Is there a query for this purpose ? Quote Link to comment Share on other sites More sharing options...
br0ken Posted June 30, 2008 Share Posted June 30, 2008 Try either of these, they make work, I'm not too sure. SELECT id FROM test ORDER BY SUM(num1,num2,num3) DESC LIMIT 1 SELCET id FROM test ORDER BY (num1+num2+num3) DESC LIMIT 1 Quote Link to comment Share on other sites More sharing options...
asmith Posted June 30, 2008 Author Share Posted June 30, 2008 i tried the second and it works. The problem is if the sum of 2 rows is equal , that query shows only 1 row. select * from table where num1+num2 are max. --> maybe 2 rows have the max number. so i could use mysql_num_rows for it to find out . I'm looking for only one query, otherwise i can use your query, save the max sum, then again run a query ke select ..... where num1+num2+num3 = the number from previous query i'm just looking for the simplest way. Quote Link to comment Share on other sites More sharing options...
rhodesa Posted June 30, 2008 Share Posted June 30, 2008 only way i can think of is: SELECT * FROM test WHERE (num1 + num2 + num3) = (SELECT MAX(num1 + num2 + num3) FROM test) 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.