I am trying to use a sub-query to pick out the first element of a table with some other filtering on it.
I am working based off a comment on this answer to a similar question. My query differs slightly because I am doing some filtering on the table generated from the sub-query.
select *
from (
select firstname, lastname
from employees
order by (lastname)
)
where
rownum = 1
AND lastname like :wildcard;
My question is: Is it possible that additional filtering like this will spoil the order from the sub-query, making this technique not work in some cases?
There is an obvious solution to this problem, where you could simply move the lastname like :wildcard
filter inside the sub-query, but the application I am working with restricts me from doing that (and I am sorry if that makes the question more obscure).
EDIT:
To try to clarify my application restriction, the lastname like :wildcard
filter cannot be in ANY from
clause sub-query.
To explain, as best as I can without making this a very complicated question, the application uses pieces of queries in many different places and will edit queries depending on context. Sometimes the application substitutes :wildcard
with column references from parent queries. Based on experimentation, this cannot be done in from
clause subqueries (though I was unable to find documentation to that effect and I can only guess at why).