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
 SQL Server 2000 Forums
 Transact-SQL (2000)
 selecting a date-based subset of a query

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2003-01-30 : 08:20:58
Michael writes "I have a simple table as follow (sample of contents only)

SessionGroup SessionDate
------------ -----------
16 1/22/2003
17 1/30/2003
18 1/29/2003
18 2/5/2003
18 2/26/2003
18 3/5/2003
22 1/15/2003
22 1/19/2003
22 2/6/2003
22 3/6/2003

and so forth. Each line has a session group and the date that session occurs, some session groups have multiple dates, and as such, multiple lines with the same sessiongroup but different dates.

What I would like is a single recordset consisting of the last date of each session and the sessiongroup number. (there's other stuff in the table, but it's not necessary information. I would very much like to avoid the use of a temporary table even though I know I could do it that way with finding the largest date of a given session group, inserting that into the temporary table, and then moving on to the next sessiongroup.

Any help is appreciated!"

ValterBorges
Master Smack Fu Yak Hacker

1429 Posts

Posted - 2003-01-30 : 08:32:58
SELECT SessionGroup, Max(SessionDate)
FROM Sessions
GROUP BY SessionGroup

Go to Top of Page
   

- Advertisement -