I'm not an Oracle expert, so I'm having trouble figuring out this simple query.
I have two tables, they have a foreign key with a 1 to many relationship. Meaning I have a list of equipment in 1 table , and a list of events associated with the equipment in the other table .
Each event has a timestamp column. All I want to do is sort by timestamp DESC and select the top 1 for each event. Esentially for each piece of equipment 1 select the most recent event.
Here's a stab I took at the query...but it doesn't work because the inner query selects the first row before it sorts them. What's the correct way to get around this in Oracle?
Thank for your help!
SELECT e.ID, ee.eventname, ee.eventtime FROM equipment e
SELECT eventname, eventtime FROM events where rownum = 1
ORDER BY eventtime DESC
ON ee.equipmentid = e.id