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
 Help With Query

Author  Topic 

rds207
Posting Yak Master

198 Posts

Posted - 2010-04-01 : 18:13:30
I need to map host_name with its associated resource name , currently i have multiple values , so i need to get distinct resource_names and its associated host_names


I cannot use distinct ,
if i write select distinct recource_name and host_name i get the values not mapped to each other ...

Here is my Sample Data

HOST_NAME RESOURCE_NAME
hcibldwin01 MOBWIN
hcibldwin01 hcibldwin01
kwbuild06 KW_prod
cadet cadet
kwbuild07 KW_prod
kwbuild07 KW_prod
kwbuild07 KW_prod
kwbuild07 KWBUILD07

There are around 246 unique resource names and may be 5-6 hostname asscoaited with it , so how do i map recource name with host_name ?

Please Help ...

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-04-01 : 19:23:33
Try this:

SELECT y.HOST_NAME, t.RESOURCE_NAME
FROM YourTable y
JOIN (SELECT DISTINCT RESOURCE_NAME) t
ON y.RESOURCE_NAME = t.RESOURCE_NAME

It's using a derived table, aliased as t.

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 -