There times (not often, but times) where its really useful to write something like...
In Postgres I can do this:
However in Oracle, there's rownum, but this doesn't work:
That doesn't work because the where clauses there is evaluated before the order by.
Can't do this either:
The inner query doesn't have the scope to pull in from table_foo anymore.
You can get around this with JOINing and filtering, but often times that subselect performance is just fine and much much more clear.
I just wish there was a real LIMIT in Oracle (or that we did our main app in Postgres).
In Postgres I can do this:
SELECT
...
(SELECT some_value from table_bar bar where bar.foo_id = foo.foo_id
order by some_date LIMIT 1) as some_value_from_bar
FROM
table_foo foo;
However in Oracle, there's rownum, but this doesn't work:
SELECT
...
(SELECT some_value from table_bar bar where bar.foo_id = foo.foo_id
and rownum = 1 order by some_date) as some_value_from_bar
FROM
table_foo foo;
That doesn't work because the where clauses there is evaluated before the order by.
Can't do this either:
SELECT
...
(SELECT some_value from ( SELECT some_value from table_bar bar
where bar.foo_id = foo.foo_id order by some_date) t1 where rownum = 1 ) as some_value_from_bar
FROM
table_foo foo;
The inner query doesn't have the scope to pull in from table_foo anymore.
You can get around this with JOINing and filtering, but often times that subselect performance is just fine and much much more clear.
I just wish there was a real LIMIT in Oracle (or that we did our main app in Postgres).