Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Mailing Lists -> Oracle-L -> Re: ** SQL WHERE clause order
A Joshi wrote:
>
> Hi,
> In a SQL statement I want a certain where clause to be done first. Is it enough to list it first as follows or do I (and can I) do something else to make it get checked first before other WHERE/AND clause are looked at. Thanks :
>
> SELECT emp_id FROM emp
> WHERE select_sen_emp_chk_first = 'Y'
> AND dept = :dept
> AND salary > :min_sal
<JUMPING AROUND>
What are you doing ? Firstly the answer to your question is a
resounding NO, and secondly your approach is totally illogical. I fear
something like 'one of the other conditions forces a to_number() which
fails if I haven't checked beforehand that I am dealing with a number'
or something as ghastly. If this is really what you have in mind, you
can very easily with decode() have a condition which depends on the
contents of another column. Never, ever depend on order.
Now if your only concern is to force the optimizer to use one specific
index, you can put an hint or the old dept+0 = :dept trick.
But I fear you are on a slippery slope. </JUMPING AROUND>
-- Regards, Stephane Faroult Oriole Software -- Please see the official ORACLE-L FAQ: http://www.orafaq.net -- Author: Stephane Faroult INET: sfaroult_at_oriole.com Fat City Network Services -- 858-538-5051 http://www.fatcity.com San Diego, California -- Mailing list and web hosting services --------------------------------------------------------------------- To REMOVE yourself from this mailing list, send an E-Mail message to: ListGuru_at_fatcity.com (note EXACT spelling of 'ListGuru') and in the message BODY, include a line containing: UNSUB ORACLE-L (or the name of mailing list you want to be removed from). You may also send the HELP command for other information (like subscribing).Received on Tue Nov 04 2003 - 16:19:28 CST
![]() |
![]() |