Two simple tables
Base table
+--------+
|id|value|
+--------+
| | |
+--------+
Event table (with a lot of data..)
+--------------+
|id|event| date|
+--------------+
| | | |
+--------------+
Then I would like to have a list of all base.value with corresponding to their last events (including values without event entries)
+----------------+
|id|lastEvt|value|
+----------------+
| | | |
+----------------+
This is a (working but) very slow attempt
SELECT *
FROM (
SELECT base.id,
event.event,
base.value
FROM base
LEFT OUTER JOIN event
ON base.id = event.id
ORDER BY event.date DESC
)
AS res
GROUP BY res.id;
I suspect there is a better/faster way of doing the query, but I don’t know how..
1 Answer