Solved

t-sql max date of table

Posted on 2014-11-17
4
129 Views
Last Modified: 2014-11-18
i'm using sql server 2008.

I have a table that looks like this:

http://sqlfiddle.com/#!3/6e117/2

How would I write a query that looks at the EVENTDATETIME column and returns the most recent concert for each artist.

So the result set would show only the most recent concert for each artist.
The result set would look something like this:

desired result set
0
Comment
Question by:maqskywalker
  • 2
4 Comments
 
LVL 65

Assisted Solution

by:Jim Horn
Jim Horn earned 100 total points
ID: 40448860
That would be a simple GROUP BY on artist, and MAX date.
SELECT Artist, Max(EventDateTime) as most_recent_event_dt
FROM TestTable
GROUP BY Artist

Open in new window

If you'd like some more reading on GROUP BY I have an image and code-heavy tutorial out there called SQL Server GROUP BY Solutions
0
 
LVL 1

Author Comment

by:maqskywalker
ID: 40449024
Jim but what if I want to show every column like on the screen shot I posted above?
0
 
LVL 9

Accepted Solution

by:
sarabhai earned 400 total points
ID: 40449059
SELECT * FROM TestTable WHERE EventDateTime IN ( SELECT  MAX(EventDateTime)  FROM TestTable GROUP BY artist )
0
 
LVL 65

Expert Comment

by:Jim Horn
ID: 40449783
Thanks for the split.  Good luck with your project.  -Jim
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now