D
DanL
I have a table like this:
Key1 Key2 UserID Phone#Called DateCalled Minutes
1 1 1 555-1111 1/1/2009 10
1 2 1 555-1111 1/1/2009 7
2 1 2 555-2222 1/1/2009 15
2 2 2 555-2222 1/2/2009 23
2 3 2 555-2222 1/3/2009 50
What is the best way to create a delete query that removes the entire rows
associated with these keys:
Key1 Key2
1 2
2 2
2 3
I want to keep a single record for each unique combination of UserID and
Phone#Called. If there are multiple values of DateCalled for a combination
of UserID and Phone#Called, I want to select the earliest value of
DateCalled. If there are multiple values of Minutes for a combination of
UserID and Phone#Called with the earliest DateCalled, I want to select the
largest value for Minutes. So when the delete query has run, the following
rows should remain:
Key1 Key2 UserID Phone#Called DateCalled Minutes
1 1 1 555-1111 1/1/2009 10
2 1 2 555-2222 1/1/2009 15
The actual table I am working with has hundreds of thousands (if not
millions) of rows and several additional columns. I need to use conditional
row filtering for these columns similar to what I have described for
DateCalled and Minutes in the example.
My current solution is a series of queries, but I am looking for something
less cumbersome, easier to maintain, and requiring less time to run. I have
used subqueries some and could see how they might be useful here, but am not
very skilled at creating them.
Key1 Key2 UserID Phone#Called DateCalled Minutes
1 1 1 555-1111 1/1/2009 10
1 2 1 555-1111 1/1/2009 7
2 1 2 555-2222 1/1/2009 15
2 2 2 555-2222 1/2/2009 23
2 3 2 555-2222 1/3/2009 50
What is the best way to create a delete query that removes the entire rows
associated with these keys:
Key1 Key2
1 2
2 2
2 3
I want to keep a single record for each unique combination of UserID and
Phone#Called. If there are multiple values of DateCalled for a combination
of UserID and Phone#Called, I want to select the earliest value of
DateCalled. If there are multiple values of Minutes for a combination of
UserID and Phone#Called with the earliest DateCalled, I want to select the
largest value for Minutes. So when the delete query has run, the following
rows should remain:
Key1 Key2 UserID Phone#Called DateCalled Minutes
1 1 1 555-1111 1/1/2009 10
2 1 2 555-2222 1/1/2009 15
The actual table I am working with has hundreds of thousands (if not
millions) of rows and several additional columns. I need to use conditional
row filtering for these columns similar to what I have described for
DateCalled and Minutes in the example.
My current solution is a series of queries, but I am looking for something
less cumbersome, easier to maintain, and requiring less time to run. I have
used subqueries some and could see how they might be useful here, but am not
very skilled at creating them.