INSERT INTO for highest dates in SQL


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.

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:

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.

Who is Participating?
Jim HornConnect With a Mentor Microsoft 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

Open in new window

btw I have an article on SQL Server GROUP BY expressions that would be a good read.
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 :-)

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
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.

All Courses

From novice to tech pro — start learning today.