Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Query assistance needed (again)
Message
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Versions des environnements
SQL Server:
SQL Server 2005
Divers
Thread ID:
01296821
Message ID:
01296825
Vues:
12
Try
SELECT * FROM mytable mt1
  WHERE Saved = (SELECT MAX(saved) FROM mytable mt2 WHERE mt2.id = mt1.id)
-- or
SELECT * FROM mytable mt1
  WHERE NOT EXISTS (SELECT 1 FROM mytable mt2 WHERE mt2.id = mt1.id 
                          AND mt2.Saved > mt1.Saved)
>Consider the table
>

>Id Bal Saved
>1 100 2/5/2008
>1 90 2/6/2008
>1 80 2/7/2008
>2 250 2/6/2008
>2 150 2/9/2008
>

>
>I am tring to create a query that will give me the following result set:
>

>Id Bal Saved
>1 80 2/7/2008
>2 150 2/9/2008
>

>i.e., one record per Id that has the newest date.
>
>Thanks,
>Einar
--sb--
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform