Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Get PK Value for unique field value
Message
From
06/10/2004 19:21:52
 
 
To
24/09/2004 13:14:28
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Miscellaneous
Thread ID:
00945785
Message ID:
00949391
Views:
11
>I want a query that will give me the first PK value for each unique "Value". So I will get back:
create table #test (pk int, value char(1))

insert into #test values ( 1,'a' )
insert into #test values ( 2,'c' )
insert into #test values ( 3,'b' )
insert into #test values ( 4,'c' )
insert into #test values ( 5,'a' )


SELECT pk, value 
FROM #test t
WHERE pk = (SELECT TOP 1 t2.pk FROM #test t2 WHERE t.value = t2.value ORDER BY value)

drop table #test
BOb
Previous
Reply
Map
View

Click here to load this message in the networking platform