Solved

t-sql max date of table

Posted on 2014-11-17
4
136 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Suggested Solutions

Naughty Me. While I was changing the database name from DB1 to DB_PROD1 (yep it's not real database name ^v^), I changed the database name and notified my application fellows that I did it. They turn on the application, and everything is working. A …
How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

752 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