December 1, 2008 at 10:57 pm
The table is somewhat like this
Create Table #tab1(
[HistoryID] [int] IDENTITY(1,1),
[IssueID] [int] NULL,
[UserID] [int] NULL,
[CreatedDate] [datetime] NULL,
)
Insert #Tab1 values(1,3,'2008-09-24 18:13:56.000')
Insert #Tab1 values(1,3,'2008-09-25 18:13:56.000')
Insert #Tab1 values(2,4,'2008-09-26 18:13:56.000')
Insert #Tab1 values(2,4,'2008-09-22 18:13:56.000')
Insert #Tab1 values(2,4,'2008-09-28 18:13:56.000')
Insert #Tab1 values(2,4,'2008-09-29 18:13:56.000')
select * from #Tab1
will display
HistoryId IssueID UserID CreatedDate
1 1 3 2008-09-24 18:13:56.000
2 1 3 2008-09-25 18:13:56.000
3 2 4 2008-09-26 18:13:56.000
4 2 4 2008-09-22 18:13:56.000
5 2 4 2008-09-28 18:13:56.000
6 2 4 2008-09-29 18:13:56.000
i want all the rows with largest createddate group by IssueId and UserID..ie..
i want one row each for each same issueid and userid with largest createdDate
Please Help...
December 1, 2008 at 11:09 pm
Like this:
Select IssueId, UserID, MAX(CreatedDate)
From #tab1
Group By IssueId, UserID
[font="Times New Roman"]-- RBarryYoung[/font], [font="Times New Roman"] (302)375-0451[/font] blog: MovingSQL.com, Twitter: @RBarryYoung[font="Arial Black"]
Proactive Performance Solutions, Inc. [/font][font="Verdana"] "Performance is our middle name."[/font]
December 1, 2008 at 11:12 pm
Try this statement :
select issueid, userid, max(createddate) from #tab1 group by issueid, userid
December 1, 2008 at 11:34 pm
Thanks for the replies i found the solution....
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy