troubleshooting Question

Get 1 row per GROUP

Avatar of psenn
psenn asked on
Microsoft SQL Server
2 Comments1 Solution82 ViewsLast Modified:
How do I get the latest UpdateDate for each UpdateUser?

This gets me the list, but I want to limit it to 1 row (the first row) per user.
SELECT UpdateUser,UpdateDate
FROM Subscription
GROUP BY UpdateUser,UpdateDate
ORDER BY UpdateUser, UpdateDate DESC



CREATE TABLE dbo.Subscription(
 SubscriptionID Integer Identity(70291,1) CONSTRAINT SubscriptionID Primary Key Nonclustered,
 SubscriptionDesc VarChar(255),
 UpdateDate datetime DEFAULT GetDate(),
 UpdateUser VarChar(50) DEFAULT suser_sname())
GO
INSERT INTO Subscription(SubscriptionDesc) VALUES ('A')
INSERT INTO Subscription(SubscriptionDesc) VALUES ('B')
INSERT INTO Subscription(SubscriptionDesc) VALUES ('C')
INSERT INTO Subscription(SubscriptionDesc) VALUES ('D')
INSERT INTO Subscription(SubscriptionDesc) VALUES ('E')
INSERT INTO Subscription(SubscriptionDesc) VALUES ('F')
INSERT INTO Subscription(SubscriptionDesc) VALUES ('G')
UPDATE Subscription SET UpdateUser = 'psenn' WHERE SubscriptionDesc='C'
UPDATE Subscription SET UpdateUser = 'psenn' WHERE SubscriptionDesc='D'
UPDATE Subscription SET UpdateDate = '1/1/1900'  WHERE SubscriptionDesc='B'
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 2 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros