How can I get the record details of an aggregate function without using a sub query?
I have a data set as follows:
CREATE TABLE SOMEDATA(
id int,
low int,
op int,
yc int,
tc int,
volume int,
Atimestamp time)
INSERT INTO SOMEDATA VALUES(5631, 5500, 5600, 5680, 5680, 300527, '13:16:12.462')
INSERT INTO SOMEDATA VALUES(5631, 5500, 5600, 5680, 5680, 301720, '13:16:13.304')
INSERT INTO SOMEDATA VALUES(5631, 5500, 5600, 5680, 5680, 302041, '13:16:13.306')
INSERT INTO SOMEDATA VALUES(5631, 5500, 5600, 5680, 5680, 302410, '13:16:13.682')
INSERT INTO SOMEDATA VALUES(5631, 5500, 5600, 5680, 5680, 302548, '13:16:15.818')
INSERT INTO SOMEDATA VALUES(5632, 5500, 5600, 5680, 5680, 302548, '13:16:15.818')
Which I query by doing:
SELECT * FROM SOMEDATA
INNER JOIN (select max(Atimestamp) as tm,id FROM SOMEDATA group by id) t
on t.tm = SOMEDATA.Atimestamp AND SOMEDATA.id = t.id
This seems like a bad way to do it though ( eg as I understand it, this query locks the table twice) - is there a better way to do this ( with HAVING perhaps )?