Solved

Query to get the latest modified records

Posted on 2008-10-24
3
703 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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

'Between' is such a common word we rarely think about it but in SQL it has a very specific definition we should be aware of. While most database vendors will have their own unique phrases to describe it (see references at end) the concept in common …
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

759 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now