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
 Retrieve distinct values

Author  Topic 

nbalraj
Starting Member

21 Posts

Posted - 2010-08-22 : 22:53:40
Hi,

I have this table

ID Country
-----------
1 Afganistan
2 Afganistan
3 Andorra
4 Angola
5 Angola
6 Argentina
7 Argentina

The output I need is
unique country name and their respective ID

Final output
1 Afganistan
3 Andorra
4 Angola
6 Argentina

Thanks for any help,
NB

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-08-22 : 23:10:46
SELECT MIN(ID) AS ID, Country
FROM YourTable
GROUP BY Country
ORDER BY ID

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

Subscribe to my blog
Go to Top of Page

nbalraj
Starting Member

21 Posts

Posted - 2010-08-23 : 21:54:11
thanx a lot
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-08-24 : 03:33:05
You're welcome.

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 -