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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 how to get max value...

Author  Topic 

sadaiyan
Starting Member

6 Posts

Posted - 2008-07-28 : 14:56:57
hello, i have three fields namely a,b,c now i'm getting max(a),max(b) and max(c) .can anyone suggest me a solution how to get the max values from those three value.I tried this query but it shows error...
select max(a1) from(select max(a) from table as a1 union select max(b) from table as a1 union select max(c) from table as a1) plz anyone give me a solution. thanks.

sadaiyan.l

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-07-28 : 14:59:46
select max(MaxColumn) as MaxColumn
from
(select max(a) as MaxColumn from table union select max(b) from table union select max(c) from table) dt

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-07-29 : 04:11:59
didnt i give you solution here:-

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=107540
Go to Top of Page

sadaiyan
Starting Member

6 Posts

Posted - 2008-07-30 : 12:40:56
Hello tkizer,
Thanks to reply me, in this solution what is dt

select max(MaxColumn) as MaxColumn
from
(select max(a) as MaxColumn from table union select max(b) from table union select max(c) from table) dt


sadaiyan.l
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-07-30 : 12:49:07
It's the alias from the derived table. You can name it anything, but an alias is required. I chose dt for Derived Table.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -