Where clause priority in Select Query

Hi All,
I have one doubt, Pls clarify
SELECT empno, ename, sal, comm
FROM emp E, dept D -- (deptno is pk for DEPT)
WHERE D.deptno = E.deptno
AND E.sal >= 3000
In WHERE clause which one will execute first (right to left or left to right
OR[b] First join conditions then after filter conditions or vice versa)
D.deptno = E.deptno
OR
E.sal >= 3000
(this is the example tables)
Because I have large volume of data with 5 tables with joins
so, pls. kindly give me the sugession for where clause.
Thanks
Naresh

It depends, the order the where clause is written in makes no difference to how the statement is processed.
In the section on Developing Efficient SQL Statements in the Performance Tuning Guide changing the order of statements in the where clause is notably missing.
There is more information in the Understanding Joins section of the same manual.

Similar Messages

  • Multiple values in where clause(IN) of select query in Cisco Cloud Portal using single field

    I can actually pass multiple values in the IN statement of select query using multiple dictionary fields in the data retrieval rule of the AFC in Cisco cloud portal like
    #dictionary.field1# = 1 and
    #dictionary.field2#=2
    select col1,col2 from table1 where col3 in (#dictionary.field1#,dictionary.field2#).
    but I want to pass mutiple values in a single field as
    #dictionary.field1#=1,2
    select col1,col2 from table1 where col3 in (#dictionary.field1#) and the query gives no data because it is taking as '1,2' instead of '1','2'.
    Please give the solution for passing multiple values in a single variable to use in IN operator of WHERE clause

    Ok, I now understand what you are trying to do. Unfortunately, you cannot inject parts of a SQL statement into a DDR through a dictionary field, which always represents a specific value (the comma in your case is attempting injection of a SQL construct to refer to multiple values). One possible solution is to arbitrarily consolidate your list of values using a delimiter that you know will not be in the values themselves such as a colon (:). Let's use 3 values as it serves as a better example.
    Set your dictionary field to a single reference to all 3 values of interest, say 'a', 'b', 'c' as:
    :a:b:c:  (you can use javascript to create this consolidated dictionary field)
    Now your query would look something like the following:
    select col1,col2 from table1 where #dictionary.field1t# like '%:'+col3+':%'
    This should achieve the desired result.

  • Can we use concatenate in where clause of a select query

    I have a select query as follows....
        SELECT ebeln ebelp belnr vgabe bwart DMBTR
                                 FROM ekbe
                                 INTO TABLE i_ekbe
                                 FOR ALL ENTRIES IN i_blck
                                 WHERE ebeln =  i_blck-ebeln AND ebelp =                                                                               
    i_blck-ebelp.
    Now i want to retrieve data from BKPF ..can i write a select query something like....
    select * from BKPF into itab
                FOR ALL ENTRIES IN i_ekbe
                where awkey = ( conatenate i_ekbe-belnr i_ekbe-gjahr )
    OR ELSE...is there any other way to link table ekbe and bseg ???

    Hi Poonam,
    SELECT ebeln ebelp belnr vgabe bwart DMBTR
    FROM ekbe
    INTO TABLE i_ekbe
    FOR ALL ENTRIES IN i_blck
    WHERE ebeln = i_blck-ebeln
    AND ebelp = i_blck-ebelp.
    select *
    from BKPF
    into  table itab
    FOR ALL ENTRIES IN i_ekbe
    where belnr = i_ekbe-belnr.
    If u want to check with AWKEY concatenate into seperate field and then use to check in where condition.
    data: lw_awkey(20) type c.
    CONCATENATE  i_ekbe-belnr  i_ekbe-gjahr  INTO lw_awkey.
    select *
    from BKPF
    into  table itab
    FOR ALL ENTRIES IN i_ekbe
    where awkey = lw_awkey
    Best regards,
    raam

  • Values from a Multi-Select in the where clause of a Select statement

    I have a web page that solicits query parameters from the user.
    The selections that the user makes will populate the WHERE clause of a Select statement.
    One of the controls on the page is a multi-select control.
    When this page posts, I would like to execute a Select statement wherein the selected values from this control appear in the .. Column IN ( <list here> ) portion of the WHERE clause.
    This is an extremely common scenario, but I cannot seem to locate a how-to or message thread that addresses this specific case.
    I have an idea that it may involve dynamic SQL or Execute Immediate, but cannot seem to pin down the answer.
    Any help would be greatly appreciated!

    anonymous - As illustrated here: Re: Search on a typed in list of values
    Scott

  • How do I modify the WHERE clause in my SQL query?

    This seems like such a straight-forward part of the report design, but I'm fairly new to Crystal Reports and I only have experience with modifying reports someone else has already written.  In this particular case, I just need to modify the WHERE clause of the SQL query.  I can select Show SQL Query and see what statement is being used to select data, but I can't find where to modify it since it's grayed out.  I see how to change the selection criteria, parameters, grouping, etc...just not the WHERE clause.  The report is linked to a database used for reporting with a table created and populated by a stored procedure.  I don't need to modify the stored procedure because the data I want to filter by is currently in the table--I just don't know how to filter by what I need.  Here's part of the query:
    SELECT "rpt_dist"."startdate", "rpt_dist"."transtype", "rpt_dist"."laborcode", "rpt_dist"."crewid", "rpt_dist"."regularhrs" FROM   "Reporting"."dbo"."rpt_dist" "rpt_dist"
    WHERE  (rpt_dist."transtype" <> 'WORK' AND rpt_dist."transtype" <> 'WMATL') AND rpt_dist."laborcode" LIKE 'S%' AND (rpt_dist."crewid" = 'HOUS' OR rpt_dist."crewid" = 'HOUS2' ...
    I would like to add another crewid to the WHERE clause.  Thanks for any input.

    1.Open the report in the crystal designer
    2.Go to the field explorer(if hidden go to view menu->field explorer)
    3.Rt. click on the database fields->choose database expert
    4.Now you will see 2 columns-Available DataSource  and Selected Tables
    5.Rt. click on the object(ex.command) available in the Selected Tables column->Choose Edit command
    6.A new Modify Command window will appear,here you can edit your SQL Query
    I get to step 4 and I see the two columns including my database and the report table, but there is no command object available.  If I right-click on my table, I can just view the Properties. ??
    As for the other tip to modify the record selection:  I don't see anywhere the other crewid values are set and if I add the one I'm missing, it doesn't modify the existing SQL Query and when I preview the report it throws off the results so that no data displays??
    I'm using Crystal Reports 11.5 if that makes a difference.  Thanks again.

  • How to dynamically update columns in a where clause to a SQL query in OSB?

    Hi Gurus,
    I have a requirement where in we need to dynamically update a where clause to a SQL query in OSB(11.1.1.6.0).
    For example:
    If the JCA sql string is "select * from emp where emp_id = 100 and emp_status ='Permanent'" now i want to change this where clause and the new query has to be like "select * from emp where emp_name like 'S%' and emp_dept like 'IT' ". basically we need to change the where clause dynamically.
    We can also use "fn-bea:execute-sql()" in a xquery but I don't want to use this function as creates a new connection.
    I have done some home work and found out --> as per the DOC "http://docs.oracle.com/cd/E23943_01/dev.1111/e15866/jca.htm#OSBDV943" section: "25.5.2 JCA Transport Configuration for Proxy and Business Services", when a business service is created by using JCA, we can see Interaction Spec Properties under JCA Transport Tab. This will have a property "SqlString' and we can over ride it. But I am unable to figure out how to over ride the value. I have tried by using Transport Headers activity but no luck. Please guide me how to achieve this?
    Thanks in advance
    Surya

    I solved my problem.
    In my header renderer, I simply added a line to set the text to the object value "label.setText( (String) value );" (where label is an instance of a JLabel.
    Thank you to who took some time to think about it.
    Marc

  • Parsing an input parameter for the where clause or record select value

    In my limited CR experience, I've always used a command database connection so that I can write my own SQL.  However, now I have to parse a  pipe delimited parameter to get my value for the where clause, so I'm selecting several tables and joining them through the Database Expert Links tab.  All works fine, but after doing that and then parsing the parameter with the below formula in the Select Expert, I notice that there is no where clause in the SQL query, and although the report eventually displays the proper values, it runs through thousands of records first.  Here is my Select Expert - Record formula:
    StringVar array Parm1;
    Parm1 := Split({?DATA_AREA}, "|");
    {SO_ORDERS.CASE_ID} = Parm1[2]
    If I change "Parm1[2]" on the last line to a valid Case ID, then there is a where clause in the SQL and the report generates immediately. 
    It seems like the record select formula is applied AFTER all of the records (without a where clause) are searched when I use the parsed parameter value, but when I hard code a valid value, it places that into the where clause BEFORE the sql is executed.  Is there a way to get the parameter parsed first and then use that parsed value in the SQL where clause?
    Thanks.
    Bill

    Yes crystal will run the query first to get 100% data and then applies record selection condition. To increase the performance you need to pass the where condition at the command level instead of report level. So you need to create a report using add command like this
    select * from tablename where field={?Parameter}
    {?Parameter} is a command level parameter.
    Now insert this report as a subreport in another report which has no connection but has a parameter
    {?DATA_AREA} and create a formula like this in the main report
    Split({?DATA_AREA}, "|")[2]
    Now right click on the subreport and go to change subreport links and add this formula from main report and link this to sub report parameter {?Parameter} without linking any database field from the subreport.
    Now your subreport runs with the where clause to get the data.
    Regards,
    Raghavendra

  • Call a function in a where clause of a select

    hello,
    is it possible to call a function in a where clause of a select????
    ex: select col1, col2
    from my_table
    where my_package.my_function(32199, 2008, col3, 'P');
    and i have error message "ORA-00920: invalid relational operator"
    FUNCTION my_function(v_matricule IN NUMBER,
              v_Year IN NUMBER,
              v_date IN DATE,
              v_type IN CHAR DEFAULT 'P')
    RETURN BOOLEAN;
    @+Rosagio

    user10225229 wrote:
    hello,
    is it possible to call a function in a where clause of a select????
    ex: select col1, col2
    from my_table
    where my_package.my_function(32199, 2008, col3, 'P');
    and i have error message "ORA-00920: invalid relational operator"
    FUNCTION my_function(v_matricule IN NUMBER,
              v_Year IN NUMBER,
              v_date IN DATE,
              v_type IN CHAR DEFAULT 'P')
    RETURN BOOLEAN;You can call a function if it returns a datatype that is supported by SQL. BOOLEAN is NOT supported by SQL.

  • Re: [iPlanet-JATO] How to make an OR in the WHERE clause of a SELECT

    Harry,
    If you get a reference to your model, you can set the
    whereClauseOverride with exactly the string you want to use. Keep in
    mind that you are dealing with a the raw SQL where clause, therefore,
    you must use the actual table column names and not the model's logical
    field names as they could be different.
    QueryModelBase queryModel = (QueryModelBase)getModel(PersonModel.class);
    // you must add the "WHERE" as well
    String whereClause = "WHERE firstName LIKE '%max' OR lastName LIKE '%max%'";
    queryModel.setWhereClauseOverride(whereClause);
    Keep in mind that this will override all where criteria: static and
    dynamic where criteria. Static criteria can be declared in your model
    class: setStaticWhereCriteriaString(STATIC_WHERE_CRITERIA).
    You could optionally get the entire SQL statement and replace the
    __WHERE__ token yourself with a string replace technique. In fact, if
    you want to add an ORDER BY, you will need to get the SQL and append to
    the end.
    queryModel.getSelectSQL();
    Hope this helps. Let me know if you have any questions
    craig
    hlamer wrote:
    Hi,
    if I add criterias to my model
    with "SelectQueryModel.addUserWhereCriterion()" they will be concated
    with AND.
    How can I add a criteria with OR?
    I want something like:
    SELECT personId, firstName, lastName
    FROM Person
    WHERE firstName LIKE "%max"
    OR lastName LIKE "%max%"
    Thanks.
    Harry
    For more information about JATO, including download information, please visit:
    http://developer.iplanet.com/tech/appserver/framework/index.jsp

    Rewritten your query wuth tags as well
    &#123;code&#125;select  "P_CIRCUITS_FIBER"."PORTS_1",
            "P_CIRCUITS_FIBER"."PORTS_2",
            CASE WHEN CPORT.ID = (select REGEXP_SUBSTR(ports_1,'[^,]+',1,1) from p_circuits_fiber)
                 THEN "CPORT"."PORT_NO" END PORT_NO_1,
            CASE WHEN CPORT.ID = (select REGEXP_SUBSTR(ports_2,'[^,]+',1,1) from p_circuits_fiber)
                 THEN "CPORT"."PORT_NO" END PORT_NO_2
    from    "CPORT",
            "P_CIRCUITS_FIBER"
    where   p_circuits_fiber.fiber_id = :P4000_CIRCUIT_NO
    and     (select REGEXP_SUBSTR(ports_1,'[^,]+',1,1) from p_circuits_fiber) = "CPORT"."PORT_NO"  "PORT_NO_1"
    and     (select REGEXP_SUBSTR(ports_2,'[^,]+',1,1) from p_circuits_fiber) = "CPORT"."PORT_NO"  "PORT_NO_2"&#123;code&#125;
    Now we can see two columns references which should not be there.
    I even not sure to understand why those two conditions are in the WHERE clause. But for sure, CPORT.ID cannot be equal to two values unless they are same.
    Is there only one row in p_circuits_fiber ?
    Nicolas.

  • How to pass the parameter in the where clause of the select statement

    Hi All,
    Iam getting one of the value from the Input otd and using this value i need to query one of the tables in oracle database and selected the table using the oracle eway otd like shown below .
    otdRISKBLOCK_1.getRISKBLOCK().select() .
    where clause in side the select takes a string parameter as Iam getting the string parameter from the input otd and passing this to where clause by creating a string literal after deployment it is giving an error saying "ORA-00920: invalid relational operator".
    can any one throw some input on this .
    Thanks in Advance
    Srikanth

    You will see this error if the search condition was entered with an invalid or missing relational operator.
    You need to include a valid relational operator such as
      =, !=, ^=, <>, >, <, >=, <=, ALL, ANY, [NOT] BETWEEN, EXISTS, [NOT] IN, IS [NOT] NULL, or [NOT] LIKE in the condition. in the sql statement.
    Can you throw some more light on how are you designing your project?

  • Clarification on using function in where clause of oracle sql query

    I have an issue in regarding function using where clause of sql query..
    We are facing performance issue while executing query, so in what ways to improve the performance of the query which i have posted below.
    select col ,case when my_function(parameter)
    from tab1 a ,tab2 b,tabl3 c
    where a.column1=b.column2
    and b.column3 =c.column6
    and my_function(parameter)>0
    Regards
    Dinesh
    Edited by: wild fire on May 18, 2012 4:15 PM

    Dinesh,
    remind that when you use a function in the where clause it normally will get started for each record in the table.
    So your answer is two-fold:
    1. make the function only start when needed by adding a function based index on the table (this will make inserts and updates slower)
    2. make the function faster by adding the DETERMINISTIC clause if possible. this will make Oracle "cache" the result of the function.
    Regards,
    Richard
    blog: http://blog.warp11.nl
    twitter: @rhjmartens
    If this question is answered, please mark the thread as closed and assign points where earned..

  • How to use a where clause in an inner query

    String approv="pend"
     query = "Select Eno From EmpLeave Where  Status_approval='"+approv+"' and Eno in (Select Eno from EmpLeave  group by Eno having count(Eno)>1)";
    bt in the result even the rows without "pend" is also displayed...
    can sumone plzz tell me where should i put my where clause exactly in the above query

    i do have multiple records with status approval as "pend"....
    Try the below:
    query = "Select Eno From EmpLeave Where  Status_approval='"+approv+"' 
    and Eno in (Select Eno from EmpLeave  group by Eno having count(distinct status_approval)>1)";

  • Creating a where clause in the LOV query box

    Hi guys is any able to help me with this one
    i have a page in my app where there is a LOV drop down now the values for this drop down comes from a table that looks like this
    users_for _form_TBL
    E_MAIL
    Vendor
    [email protected]
    oracle
    [email protected]
    sap
    [email protected]
    IBM
    [email protected]
    Oracle
    [email protected]
    intergraph
    So my syntax for the LOV i mentioned looks like this
    select VENDOR as display_value, VENDOR as return_value
      from form_user_tab where E_MAIL = :APP_USER
    order by 1 ;
    so if [email protected] logs onto the app and has to make a selection on the LOV it would only display the vendors relative to his E_MAIL like oracle ,sap, IBM then he hits the submit button on the page then the vendor that he selected is inserted into another table .What i did on the insert table was create a trigger that after a vendor is inserted the trigger inserts a 1 into a column called assessed .
    What i did after this was add a select in the where clause of the LOV so that it would check in the insert table if that vendor had been chosen before and not display it again to be selected  my syntax the second time around in the SQL query box was
    select VENDOR as display_value, VENDOR as return_value
      from users_for _form_TBL where E_MAIL = :APP_USER
    and (select 'vendor' , 'ASSESSD' from inserted _tbl_imp is null);
    order by 1 ;
    But im getting an error any ideas guys .Thank you

    Hay man thanks for that info on the Tom Kyte Blog 
    --(the code you gave me )
    select 
        u.vendor display_value 
      , u.vendor return_value
    from 
        users_for_form_tbl u 
    where 
        u.e_mail = :app_user 
    and not exists (select null from inserted_tbl_imp i where u.vendor = i.vendor) 
    order by 
        u.vendor 
    --(After the error i tried )Then when i got the error i try'd using 'or exists'  like this
    --(code)
    where 
        u.e_mail = :app_user 
    and not exists (select null from inserted_tbl_imp i where u.vendor = i.vendor) 
                          or exists (select null from inserted_tbl_imp i where u.vendor = i.vendor)
    order by 
        u.vendor 
    But the all the vendors that where in the  same in the insert table came up in the drop down list  example is oracle was assessed before then only oracle would appear in the drop down list  and if it was assessed 3 times it would come up 3 times
    --Then i tried to select where 'Assessed' is null   ('Assessed' is a column in the insert table  which i created a trigger on to insert 1 in the 'ASSESSED' column  when a vendor is begin assessed  )  
    --(code)
    where 
        u.e_mail = :app_user 
    and not exists (select 'ASSESSED' from inserted_tbl_imp i where 'ASSESSED' is null ) 
    order by 
        u.vendor 
    This try didnt return any vendors at all
    --Then i tried distinct
    --(code)
    where 
        u.e_mail = :app_user 
    and not exists (select distinct 'VENDOR',  from inserted_tbl_imp i where u.vendor = i.vendor) 
    order by 
        u.vendor 
    This gave me a LOV ERROR
    This is what i have tried so far there where others syntax's i tried last night as well  but most of them came back as errors . Thanks again for you time and help  fac586  

  • SQL's WHERE clause priority order?

    Hi Experts,
    Example: My requirement is -- Select a record/sales order from VBAK where AUART = my_doc_type_1
    if I do not found any record, then I have to look up as Select a record/sales order from VBAK where AUART = my_doc_type_2
    So, am writing the SQL as below.
    SELECT vbeln INTO my_vbeln FROM vbak
    WHERE auart IN ( my_doc_type_1, my_doc_type_2 ).
    Pls. let me know,
    1) My assumption is that, system FIRST look for my_doc_type_1 record, if it does not found any such, then system will look for my_doc_type_2 record, am I correct?
    2)if so, the PRIORITY is in the order in which we hv given in paranthesis?
    3) Say, there are 2 records with same VBELN (I knew, its impossible having 2 recoords with same key!! just for example) and hving the AUART values as my_doc_type_1 and my_doc_type_2 like below
    12345678 -
    my_doc_type_1
    12345678 -
    my_doc_type_2
    So, in this case system will select BOTH records?
    Actually, i dont have SAP, so i can not do a quik test.
    Thank you

    Hi,
    It's so funny that you said:
    Actually, i dont have SAP, so i can not do a quik test.
    So, with your current query:
    SELECT vbeln INTO my_vbeln FROM vbak
    WHERE auart IN ( my_doc_type_1, my_doc_type_2 ).  "if i'm not wrong, you will get syntax error in this select query
    It's always returns only one record. If you wanted to get all you must declare an internal table to hold your results:
    SELECT vbeln INTO TABLE my_itab FROM vbak
    WHERE auart IN ( my_doc_type_1, my_doc_type_2 ).
    REgards,

  • How to include an always-true where clause to an infostore query

    Hi all.  Iu2019m trying to crawl my way out of a coding nightmare and was wondering:  Is there any type of benign where clause that can be appended to an infostore query and always guarantee the same result (true) with no performance implications ?  Iu2019m looking for the equivalent of how u201C1=1u201D functions in the following statement for example:
    select employees.id, employees.name from employees where employees.name = u2018john doeu2019 and 1=1
    So, for example, I want something like:
    select si_name, si_schedule_status from ci_appobjects where si_name = 'someobjectname' and 1=1
    Is there anything that can silently pass-thru an always "true" evaluation?  I thought of using " ...where xyz and SI_ID is not null " but still need to flesh it out.
    Thanks in advance.

    The "no performance implication" would be a bit difficult, since the CMS would have to parse anything you've put on. 
    To minimize the performance hit, you can always do a check against an indexed property, such as 'and SI_ID < 0'.
    I'm going to guess here that you've got a broken recursion or loop that you're using to construct a query, and need a terminating token.  If so, why not just post-process out the last clause before executing?
    By the way, because of some quirks with the query language, 1=1 will likely not work.
    Sincerely,
    Ted Ueda

Maybe you are looking for

  • Improper cuts appearing in my final output with Quicktime

    Hi everyone. I've been struggling to output what, in my opinion, is a fairly simple project I've edited from an old home video (originally shot on miniDV). It's mostly just cuts and some simple text titles. Forgive me for some ignorance regarding Fin

  • Balance Sheet marked wrongly as P & L account

    Hello Experts Our client has wrongly created few Balance Sheet GL codes as P & L accounts. Also, he did the carryforward the balance to the next financial year. Now the balanc is lying in "P&L appropriation account" Kindly advise the following three

  • Selling ebooks to schools in bulk.

    This is more of a delivery question to the end user. I got a request from a school that wants to order my book for all their students in their class. Does Apple provide a mechanism for the school administrator in the iBookstore? I could sell the scho

  • Password protect individual pages, web gallery?

    Hello; When hosted by .mac Is it possible to password protect a single page (or photo gallery)? Also, can we allow people to post on the Blog via password? TIA -T

  • Get redo sequence number against SCN

    hi all, environment is oracle 10gr2(10.2.0.5.0)... 1 PROD Server 1 DR Server (Dataguard Configuration) 1 Reporting Server (replication is configured via oracle streams on some large tables....) Due to shortage of disk space i need to remove archivelo