I am having a hard time converting stored procedures from SQL Server to Oracle to have our product compatible with it.
I have queries which return the most recent record of some tables, based on a timestamp :
SQL Server:
SELECT TOP 1 *
FROM RACEWAY_INPUT_LABO
ORDER BY t_stamp DESC
=> That will return me the most recent record
But Oracle:
SELECT *
FROM raceway_input_labo
WHERE rownum <= 1
ORDER BY t_stamp DESC
=> That will return me the oldest record (probably depending on the index), regardless of the ORDER BY statement!
I encapsulated the Oracle query this way to match my requirements:
SELECT *
FROM
(SELECT *
FROM raceway_input_labo
ORDER BY t_stamp DESC)
WHERE rownum <= 1
and it works. But it sounds like a horrible hack to me, especially if I have a lot of records in the involved tables.
What is the best way to achieve this?