I'm trying to query a join of two tables, and do it in a single query if possible (rather than one query, then a second one using results from the first). Forgive my bone-headedness - I still have a ways to go to grok sql...
(simplified)
Table 1: Events
EventID
Title
FollowupText
Table 2: EventDates
DateID
EventID
Date
Each event has multiple dates. I want to select the title, description, and LATEST date for each event. I started with:
SELECT DISTINCT Events.* FROM Events, EventDates WHERE EventDates.EventID=Events.EventID
but how do I tell it WHICH Date I want it to use? I want the MAX date, but I tried
SELECT MAX(EventDates.Date) AS LastDate, Events.EventID, Events.Title, Events.FollowupText FROM Events LEFT JOIN EventDates ON Events.EventID=EventDates.EventID
(based on reading some examples from other posts on PhpBuilder) and get a fatal error. It seems I can select just MAX(EventDates.Date), but as soon as I add any Events fields to the Select MySQL doesn't like it.
I'd also like to sort the results by LastDate, but once I get the query working that shouldn't be too difficult.
If possible I'd like to do it without subqueries. The host for this site is using MySQL 4.x but I haven't upgraded my local dev machine yet - still 3.x here.