MySQL Forums
Forum List  »  Newbie

Selecting all from one table and a MAX value from another table
Posted by: Greg Knox
Date: July 23, 2019 11:39AM

I have two tables: Sessions and SessionData

Sessions
--------------
SessionID
DateCreated

SessionData
--------------
SessionDataID
SessionID
DataTime

I'm wanting to grab all rows from Sessions and then to figure out the length of each session I'm wanting to grab the MAX DataTime value from SessionData.

I'm trying this query but it's not getting the result I want...

SELECT s.*, MAX(d.X) FROM Sessions AS s LEFT JOIN SessionData AS d ON s.SessionID = d.SessionID ORDER BY s.DateCreated DESC

I'd like to end up with a list of Session IDs, DateCreated, and then the maximum DataTime that relates to each Session. Something like...

1, 2019-07-03, 4839
2, 2019-07-02, 4011
3, 2019-07-01, 3281

What am I missing?

Thanks!

Options: ReplyQuote


Subject
Written By
Posted
Selecting all from one table and a MAX value from another table
July 23, 2019 11:39AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.