|
Hey, its a mix of misunderstanding and bad explanation so I'll have another go.
Say my user_id in watch is 1. Get my watch_id's in watch.
Then, get the first instance where watch_id (in watch) = user_id (in events) ordered by time DESC.
The query you suggested for some reason doesn't put them in order of time. I also need the user_id's in event to be distinct so theres only one instance of them in the results.
The best I've got is with this query:
SELECT DISTINCT watch_id FROM watch w JOIN events e ON e.user_id = w.user_id WHERE w.user_id = 1 ORDER BY e.time DESC
However, even though it does give me the distinct user_id rows in events based on the watch_id's in watch. However, they're STILL not ordered by time.
If I turn it into this:
SELECT * FROM watch w JOIN events e ON e.user_id = w.user_id WHERE w.user_id = 1 ORDER BY e.time DESC
It is in order of time, but its not distinct!
I hope this clarifies things slightly.
|