Removing tables with a join in SQL Server

I'm new to this DBA thing and I've been tasked with removing duplicates from a couple of tables. I'm working in SQL Server. They all have a field called LAST_UPD that tracks their last update. All the tables join to TABLE1 and each user is identified by TABLE1.ALIAS_KEY. The join is below. I'm wondering how to clean out all the duplicate rows and keep the most recent entries from Table2. Thanks for the help!

FROM dbo.Table1 T1
LEFT JOIN dbo.Table2 T2
    ON (T1.PARROW = T2.PARROW)

Answers


Assuming (and I might be incorrect) that last updated is unique you can do:

DELETE FROM dbo.Table2 T2 WHERE T2.LAST_UPD NOT IN
    (SELECT max(LAST_UPD) FROM dbo.Table2 T2 
        LEFT JOIN dbo.Table1 T1 ON (T1.PARROW = T2.PARROW)
        GROUP BY T1.ALIAS_KEY) 

Need Your Help

What is a DSL and where should I use it?

theory dsl

I'm hearing more and more about domain specific languages being thrown about and how they change the way you treat business logic, and I've seen Ayende's blog posts and things, but I've never really

Convert text into symbols, then convert symbols into sound

android android-widget morse-code

I'd like to know how to let a user input text ex. "TEXT", then have my app convert that "TEXT" into something like "@&^@", then have my app recognize "@&^@" as 4 different letters, ex. "@"

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.