Solved

Query to get the latest modified records

Posted on 2008-10-24
3
706 Views
Last Modified: 2012-08-13
My table A contains records with multiple entries of same ID (Attached Table A structure) also it contains modified date column as well.

Now i require a query to get only the latest modified records in my result set.(Attached the expected result as well). Please help
TableExpectedresult.xls
0
Comment
Question by:tks_g100
3 Comments
 
LVL 9

Accepted Solution

by:
jamesgu earned 200 total points
ID: 22798961
select * from Table_A a
where not exists ( select 1 from Table_A b where a.asset_id = b.asset_id and b.modified_date > a.modified_date)

0
 
LVL 59

Assisted Solution

by:Kevin Cross
Kevin Cross earned 100 total points
ID: 22799136
SELECT *
FROM Table_A a
INNER JOIN (SELECT asset_id, max(modified_date) AS max_modified_date FROM Table_A GROUP BY asset_id) b
ON a.asset_id = b.asset_id AND a.modified_date = b.max_modified_date
0
 

Author Closing Comment

by:tks_g100
ID: 31509770
Thanks for the query. Both yielded the results
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question