Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Query assistance needed (again)
Message
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Environment versions
SQL Server:
SQL Server 2005
Miscellaneous
Thread ID:
01296821
Message ID:
01296826
Views:
6
>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
><pre>
>
>I am tring to create a query that will give me the following result set:
><pre>
>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
SELECT YourTable.Id,
       YourTable.Bal,
       YourTable.Saved
FROM YourTable
INNER JOIN (SELECT Id, MAX(Saved) AS Saved
                   FROM YourTable
            GROUP BY Id) Tbl1
      ON YourTable.Id    = Tbl1.Id AND
         YourTable.Saved = Tbl1.Saved
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Previous
Reply
Map
View

Click here to load this message in the networking platform