I doubt the speed and result of the below queries. Can someone give me an explanation on them? (These queries are written for an Oracle database)
Let's say I have a table table1 (ID, itemID, trnx_date, balance, ...) . I want to get the last item balance.
Request 1:
SELECT balance FROM table1 WHERE ID = (SELECT MAX (ID) from table1 WHERE itemID = item_id);
Request 2:
SELECT balance FROM table1 WHERE itemID = item_id AND rownum = 1 ORDER BY ID DESC;
where item_id is a variable.
So, do these two queries perform the same result? And which one is faster or is there any other query that is faster than them?
thanks