I have the following table (ID column exists but not shown below) :
Course | DateComplete | |
---|---|---|
[email protected] | Running | 01/01/2021 |
[email protected] | Running | |
[email protected] | Running | |
[email protected] | Walking | |
[email protected] | Walking | |
[email protected] | Walking |
I'd like to know if it is possible to delete all duplicate (of Email&Course) records from my table, but also ensuring that no records with a value in DateComplete are deleted.
So after running the query I would have :
Course | DateComplete | |
---|---|---|
[email protected] | Running | 01/01/2021 |
[email protected] | Walking |
You just need a query with an aggregation such as
SELECT Email, Course, MAX(DateComplete) AS DateComplete
INTO [dbo].[new_table]
FROM [dbo].[current_table]
GROUP BY Email, Course