Need a query to remove duplicates but retain oldest and latest dates from 2 different fields

I have a query that i need to remove duplicates based on "Account_Number" field.
but also need to retain "oldest"  date from "schedules start date" and "Newest" date from "Scheduled End Date".

Based on example below:
Account_Number	Account_Name	Account_Track_Code	Schedule_Start_Date									Schedule_End_Date
811138888	   A SHOP SUPPLY	    9A999     			10/16/2013 10:57:00 AM <-- NEED THIS DATE		10/16/2013 10:57:00 AM
811138888	   A SHOP SUPPLY	    9A999     			8/29/2014 10:02:00 AM							8/29/2014 10:02:00 AM
811138888	   A SHOP SUPPLY	    9A999     			4/2/2015 1:41:00 PM								4/2/2015 1:41:00 PM
811138888	   A SHOP SUPPLY	    9A999     			4/2/2015 1:42:00 PM								4/2/2015 1:42:00 PM  <---NEED THIS DATE


QUERY RESULT:
Account_Number	Account_Name	Account_Track_Code	Schedule_Start_Date				Schedule_End_Date
811138888	   A SHOP SUPPLY	    9A999     			10/16/2013 10:57:00 AM		4/2/2015 1:42:00 PM  <  FINAL RESULT

Open in new window



Thanks
fordraiders
LVL 3
FordraidersAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Hamed NasrRetired IT ProfessionalCommented:
Try:
DELETE  *
FROM yourTable As b
WHERE b.Account_Number & b.Schedule_Start_Date
Not In (Select b.Account_Number & m from (SELECT b.Account_Number, Min(b.Schedule_Start_Date) AS m FROM yourTable As b GROUP BY b.Account_Number));

Open in new window

FordraidersAuthor Commented:
hnasr,
Ok, I did no mean literally delete the duplicated, but just remove them from the query, so the account number is distinct.

Thanks for replying.
fordraiders
Hamed NasrRetired IT ProfessionalCommented:
Try this:

SELECT *
FROM yourTable As b
WHERE b.Account_Number & b.Schedule_Start_Date
In (Select b.Account_Number & m from (SELECT b.Account_Number, Min(b.Schedule_Start_Date) AS m FROM yourTable As b GROUP BY b.Account_Number));

Open in new window

Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

Rey Obrero (Capricorn1)Commented:
try this
SELECT DISTINCT T.Account_Number, T.Account_Name, (SELECT Min(T1.Schedule_Start_date)
FROM tableFord AS T1 Where T.Account_Number=T1.Account_Number 
) AS Schedule_Start_date, (SELECT Max(T1.Schedule_end_date)
FROM tableFord AS T1 Where T.Account_Number=T1.Account_Number 
) AS Schedule_End_date
FROM tableFord AS T;

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Rey Obrero (Capricorn1)Commented:
or if your table is as simple as you posted it, you can simply use

SELECT tableFord.Account_Number, tableFord.Account_Name, Min(tableFord.Schedule_Start_date) AS MinOfSchedule_Start_date, Max(tableFord.Schedule_End_Date) AS MaxOfSchedule_End_Date
FROM tableFord
GROUP BY tableFord.Account_Number, tableFord.Account_Name;
FordraidersAuthor Commented:
Thanks to all
Hamed NasrRetired IT ProfessionalCommented:
Welcome!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.