Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

t-sql max date of table

Posted on 2014-11-17
4
Medium Priority
?
140 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 66

Assisted Solution

by:Jim Horn
Jim Horn earned 400 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 1600 total points
ID: 40449059
SELECT * FROM TestTable WHERE EventDateTime IN ( SELECT  MAX(EventDateTime)  FROM TestTable GROUP BY artist )
0
 
LVL 66

Expert Comment

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

Featured Post

Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

Question has a verified solution.

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

     When we have to pass multiple rows of data to SQL Server, the developers either have to send one row at a time or come up with other workarounds to meet requirements like using XML to pass data, which is complex and tedious to use. There is a …
In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

718 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