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
 SQL Server 2008 Forums
 Transact-SQL (2008)
 how to select max value from the table

Author  Topic 

gangadharye
Starting Member

3 Posts

Posted - 2011-05-09 : 13:28:56
How to select the maimum value from the below table

tabe name: Gang
a b c d
4 9 1 5
14 19 11 95
64 39 41 35
74 45 51 65

Gangadhar Y

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2011-05-09 : 13:32:40
you mean the maximum value accross all columns and all rows? or the maximum value of a specific column?

check out Books Online for the MAX function.

Be One with the Optimizer
TG
Go to Top of Page

gangadharye
Starting Member

3 Posts

Posted - 2011-05-10 : 00:30:19
Hi TG,

to select the maximum value in the table
eg: 95 is maximum value in the table

Gangadhar Y
Go to Top of Page

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2011-05-10 : 13:28:42
There's no real slick and efficient way to do that. The need itself may be a sign that the database design is not good. But one way could be:

select max([allCols])
from (
select max(a) as [allcols] from gang union
select max(b) from gang union
select max(c) from gang union
select max(d) from gang
) d


Be One with the Optimizer
TG
Go to Top of Page

gangadharye
Starting Member

3 Posts

Posted - 2011-05-11 : 01:03:17
Thanks TG for the help...


Gangadhar Y
Go to Top of Page
   

- Advertisement -