Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Get PK Value for unique field value
Message
De
06/10/2004 19:21:52
 
 
À
24/09/2004 13:14:28
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Divers
Thread ID:
00945785
Message ID:
00949391
Vues:
12
>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
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform