INSERT INTO for highest dates in SQL

Hi

I'm really new to SQL.

I'm trying to create a table, using INSERT INTO, which will take just the PI data and the Pres_Start dates where the Pres_Start date is the latest, e.g.

PI    DATE
A     12/10/2013
B     13/10/2013
A     18/10/2013
C     04/09/2013
D     21/08/2013
C     06/10/2013

would create a table with the following:

PI
A    18/10/2013
B    13/10/2013
C    06/10/2013
D    21/08/2013

I've searched all over, but can't find anything that works.  I would have thought this would have been fairly simple, but not to me!

500 points for a quick and working answer.

Thanks
Sarah
ScuzzyJoAsked:
Who is Participating?
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.

Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
>I'm trying to create a table, using INSERT INTO
Okay.  To both create a new table and insert rows into it using one statement it would be SELECT .. INTO.  In most situations a developer would do both in separate statements.
SELECT pi, MAX(Pres_Start) as max_date
INTO new_table
FROM your_table
GROUP BY pi

Open in new window

btw I have an article on SQL Server GROUP BY expressions that would be a good read.
0

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
ScuzzyJoAuthor Commented:
Hi Jim

It works perfectly, thank you.  It's much simpler than the various solutions a Google search was bringing up too, so I'm very happy :-)

Thanks
Sarah
0
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
Yeah we're suckers for points here, and once you're a paying member you get to avoid all of the advertisiting that's the norm on sites like stackoverflow.

Thanks for the grade.  Good luck with your project.  -Jim
0
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 Development

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.