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)
 Selecting lowest value from multiple columns

Author  Topic 

SmallTime
Starting Member

1 Post

Posted - 2011-08-20 : 18:11:46
Wonder if someone would be kind enough to help me out here.

How can I amend the following so to only select the profile with the lowest value?

Select
Profile1,
Profile2,
Profile3,
Profile4

from TblSample


- Profiles are an integer between 1 - 9
- Profiles might be repeated so that 2 or more profiles could be the same number
- The fields aren't mandatory so some profiles might be null or empty.


Many thanks
SmallTime

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2011-08-20 : 21:43:47
[code]
select col, min(p)
from (
select col, Profile1, Profile2, Profile3, Profile14
from sometable
) t
unpivot
(
p
for c in ([Profile1], [Profile2], [Profile3], [Profile4])
) p
group by col
[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -