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 2005 Forums
 Transact-SQL (2005)
 Select Query

Author  Topic 

lemondash
Posting Yak Master

159 Posts

Posted - 2009-07-29 : 07:01:06
Morning,

I have been asked to write a query that am not sure how to do.

I have three colunms sName,iCode,sDom in a table. Example of the data is below.

Modern Times Group AB Cl A,56853,SE
Modern Times Group AB Cl B,56853,SE
Modern Times Group MTG AB,164025,SE
Modern Water,157097,GB
Modernform Group PCL,38159,TH
Modernform Group PCL Fgn,38159,TH
Modernform Group PCL NVDR,38159,TH

Now i want to return the icode with a distinct value, but also return any one of the sName values. I don't mind which one is return for each icode.

any help would be great

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-07-29 : 07:03:47
[code]
select icode, min(sName)
from yourtable
group by icode
[/code]


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

Go to Top of Page

lemondash
Posting Yak Master

159 Posts

Posted - 2009-07-29 : 07:10:41
Cheers, you're a star.

I didn't realise it was that easy to do.

quote:
Originally posted by khtan


select icode, min(sName)
from yourtable
group by icode



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



Go to Top of Page
   

- Advertisement -