Microsoft
Software
Hardware
Network
Question : How to get unique records based on maximum date?
Hi - very new to SQL Server so please forgive me(!)
I have a table with data:
UNIQUE_ID SHARED_ID DATE_MODIFIED COMMENT
1 101 15/ 01/2000 HELLO
2 102 16/01/2000 TEST
3 101 20/01/2005 NEWER COMMENT
4 102 17/03/2007 NEWER COMMENT
5 103 01/01/2009 ONLY ONE COMMENT
What is the SQL syntax to return the latest (by date modified) comment for each shared ID but also returning the unique id?
So, I would expect the following result:
UNIQUE_ID SHARED_ID DATE_MODIFIED COMMENT
2 102 16/01/2000 TEST
3 101 20/01/2005 NEWER COMMENT
5 103 01/01/2009 ONLY ONE COMMENT
Many thanks for your time in helping me.
Answer : How to get unique records based on maximum date?
Slightly different approach:
SELECT t1.*
FROM SomeTable t1 INNER JOIN
(SELECT t2.SHARED_ID, MAX(t2.DATE_MODIFIED) AS DATE_MODIFIED
FROM SomeTable t2
GROUP BY t2.SHARED_ID) z ON t1.SHARED_ID = z.SHARED_ID AND t1.DATE_MODIFIED = z.DATE_MODIFIED
Random Solutions
Microsoft Virtual Environment - SQL Server 2005/SQL Server 2008
Deleting Unmatched Records MS Acess 2000
Access to OWA 2010 is very slow
Store file in mysql using connector.net and blob field
Windows Server 2008 R2 iSCSI Initiator and HP D2D CHAP issue
Two SCCM primary site in active directory
Unable To Add Outlook Account
How do I boot from san HP BL460c G6 and HP XP 240000
When ActiveX control on form changes, apply new value to another control on form.
WCF Problem: The private key is not present in the X.509 certificate.