Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
sepia
Starting Member
2 Posts |
Posted - 2006-03-15 : 11:28:35
|
| Hi all. I'm looking for assistance to get the greatest value from 3 or more different columns. I'm assuming that the best way is to put the columns into a temp table and use 'max' function to return the greatest value but don't know how to code it. Thanks in advance. |
|
|
Srinika
Master Smack Fu Yak Hacker
1378 Posts |
Posted - 2006-03-15 : 12:03:24
|
| U need max of 3 or more columns per record ?ormax of 3 or more columns for all records ?means u need results per record or just one results ?Give some sample data & the results u expect |
 |
|
|
sepia
Starting Member
2 Posts |
Posted - 2006-03-15 : 16:33:40
|
| The values would be read from different tables (ex: 1st value selected from table1, 2nd value selected from table2, 3rd value selected from table3, etc.). Would I need to put these value into a temp table then use the max function to select the value that is the greatest? How would I code that? Thanks again. |
 |
|
|
Srinika
Master Smack Fu Yak Hacker
1378 Posts |
Posted - 2006-03-15 : 16:37:55
|
| Again my Question isU have 1 rec in each table ?or more than 1 rec in each table ?if more than 1 rec in each table, how do u want to have the max (Max of what)Give some sample data & expected results |
 |
|
|
mmarovic
Aged Yak Warrior
518 Posts |
Posted - 2006-03-15 : 17:20:37
|
| No, the best way is to play with case a litle bit. We had a small contents a few month ago about the fastest solution for that exact problem and case solution won. |
 |
|
|
DustinMichaels
Constraint Violating Yak Guru
464 Posts |
Posted - 2006-03-15 : 17:25:17
|
| [code]SELECT MAX(a.Value)FROM (SELECT MAX(Table1.Value) As Value FROM Table1 UNION ALL SELECT MAX(Table2.Value) As Value FROM Table2 UNION ALL SELECT MAX(Table3.Value) As Value FROM Table3) a[/code] |
 |
|
|
mmarovic
Aged Yak Warrior
518 Posts |
Posted - 2006-03-17 : 07:26:17
|
| Sorry, I missread the problem, Dustin's solution is good one. |
 |
|
|
|
|
|