Doubt in Select Query

Hi,
I want to get data from 2 table which query is effeicient one
by seeing performance...
1. using for all entries statement
2. Get data using join query.
Thanks in advance

FOR ALL ENTRIES is better for some reasons,
--> If the data is huge , then some times JOIN may end up in TIME OUT error
--> FOR ALL ENTRIES will use the INDEXEs of the tables and improves the performance

Similar Messages

  • Doubts in Select query

    Hai,
    I have problem in my select query,
    My previous select query:
      SELECT  rrcty 
            ryear 
            rbukrs
            rzzpspid 
            SUM( hslvt )
            SUM( hsl01 )
            SUM( hsl02 )
            SUM( hsl03 )
            SUM( hsl04 )
            SUM( hsl05 )
            SUM( hsl06 )
            SUM( hsl07 )
            SUM( hsl08 )
            SUM( hsl09 )
            SUM( hsl10 )
            SUM( hsl11 )
            SUM( hsl12 )
            SUM( mslvt )
            SUM( msl01 )
            SUM( msl02 )
            SUM( msl03 )
            SUM( msl04 )
            SUM( msl05 )
            SUM( msl06 )
            SUM( msl07 )
            SUM( msl08 )
            SUM( msl09 )
            SUM( msl10 )
            SUM( msl11 )
            SUM( msl12 )
             FROM zzsl5t
           INTO TABLE it_erbproj
             WHERE rldnr       EQ  c_rldnr        AND
                rrcty      EQ  c_rrcty        AND
                ryear       EQ  v_srr_fyear    AND
                rbukrs      EQ  v_srr_ccode    AND
                racct      EQ  v_racct        AND
                rzzpspid  IN r_zzpspid         
             GROUP BY  RRCTY ryear RBUKRS rzzpspid.
    now i want change the above select query as,
    If user enters input period 03 means,
    i have to select
    SELECT  rrcty 
            ryear 
            rbukrs
            rzzpspid 
            SUM( hslvt )
            SUM( hsl01 )
            SUM( hsl02 )
            SUM( hsl03 )
            SUM( mslvt )
            SUM( msl01 )
            SUM( msl02 )
            SUM( msl03 )
    only, not to select all the periods.
    how can i give fields dynamically.
    please suggest me.
    Elamaran

    Duplicate message. Please close this one and look at my answer Doubt in Select query.

  • Small doubt in select query

    i want to count the no. of employees whose endda = '31/12/9999' and stat2 = '3'.
    tables are pa0000.
    can anyone tell me the select query?

    DATA: w_noemp TYPE i.
    SELECT COUNT(*) INTO w_noemp FROM  pa0000
           WHERE  endda  = '99991231'
           AND    stat2  = '3'.

  • Doubt in SELECT query (11.2.0.2.0)

    I have 3 tables
    1. ADBO.SECMASTER_DTL_EXT_HST_TBL
    2. BDBO.SECMASTER_DETAIL_EXT_HIST
    3. ADBO.SPOKE_TO_HUB_SEC_MTCH_TBL
    ADBO.SECMASTER_DTL_EXT_HST_TBL and BDO.SECMASTER_DETAIL_EXT_HIST have exactly the same table structure.
    Now, I need to find out the records from table BDO.SECMASTER_DETAIL_EXT_HIST with the max effective_date
    which do not match to the effective_date in ADBO.SECMASTER_DTL_EXT_HST_TBL. In the results table I need to report the diff effective dates from the 2 tables if they do not match.
    Also, SRC_INTFC_INST has to be 140 in both 1 and 2 tables. Further security_alias of table 1 has to match with spoke_sec of table 3
    and security_alias of table 2 has to match with hub_sec of table 3.
    For the data I have , I am getting 2 rows whereas I am expecting only 1 row. Can anyone suggest why this is so??
       SELECT
             B.SECURITY_ALIAS,
              TO_CHAR (C.SPOKE_PAID),
              A.SECURITY_ALIAS,
              TO_CHAR (C.HUB_PAID),
              'SECMASTER_DETAIL_EXT_HIST',
              'EFFECTIVE_DATE',
              NVL ( (CAST (B.EFFECTIVE_DATE AS VARCHAR2 (100))),
                   'No Records Found'),
              NVL ( (CAST (A.EFFECTIVE_DATE AS VARCHAR2 (100))),
                   'No Records Found')
         FROM ADBO.SECMASTER_DTL_EXT_HST_TBL  A,
              (SELECT SECURITY_ALIAS, EFFECTIVE_DATE, SRC_INTFC_INST
                 FROM [email protected]) B,
              ADBO.SPOKE_TO_HUB_SEC_MTCH_TBL C
        WHERE     A.SRC_INTFC_INST = 140
              AND B.SRC_INTFC_INST = 140
              AND A.SECURITY_ALIAS = C.spoke_sec
              AND b.security_alias = C.HUB_SEC
              AND TO_CHAR (a.effective_date,'DD-MON-YYYY')
               <> TO_CHAR((SELECT MAX (h.effective_date)
                        FROM [email protected] H                    
                         where h.security_alias = b.security_alias
                             AND h.src_intfc_inst = b.src_intfc_inst), 'DD-MON-YYYY')
            and a.security_alias='6313';
    Insert into ADBO.SECMASTER_DTL_EXT_HST_TBL
       (SECURITY_ALIAS, SRC_INTFC_INST, EFFECTIVE_DATE)
    Values
       (6313, 140, TO_DATE('05/15/2013 00:00:00', 'MM/DD/YYYY HH24:MI:SS'));
    Insert into BDBO.SECMASTER_DETAIL_EXT_HIST
       (SECURITY_ALIAS, SRC_INTFC_INST, EFFECTIVE_DATE)
    Values
       (327667, 140, TO_DATE('05/20/2013 00:00:00', 'MM/DD/YYYY HH24:MI:SS'));
    Insert into BDBO.SECMASTER_DETAIL_EXT_HIST
       (SECURITY_ALIAS, SRC_INTFC_INST, EFFECTIVE_DATE)
    Values
       (327667, 140, TO_DATE('05/15/2013 00:00:00', 'MM/DD/YYYY HH24:MI:SS'));
    Insert into ADBO.SPOKE_TO_HUB_SEC_MTCH_TBL
       (SPOKE_PAID, SPOKE_SEC, LAST_HELD_DATE, PREV_HELD_DATE, HUB_PAID, HUB_SEC)
    Values
       ('L3083                                                                                        ', 6313, TO_DATE('07/18/2013 22:15:46', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('07/15/2013 22:15:30', 'MM/DD/YYYY HH24:MI:SS'), 'L3083                                                                                        ',
        327667);
    CREATE TABLE ADBO.SECMASTER_DTL_EXT_HST_TBL
      SECURITY_ALIAS                  NUMBER        NOT NULL,
      SRC_INTFC_INST                  NUMBER        NOT NULL,
      EFFECTIVE_DATE                  DATE          NOT NULL
    CREATE TABLE BDBO.SECMASTER_DETAIL_EXT_HIST
      SECURITY_ALIAS                  NUMBER,
      SRC_INTFC_INST                  NUMBER,
      EFFECTIVE_DATE                  DATE
    CREATE TABLE ADBO.SPOKE_TO_HUB_SEC_MTCH_TBL
      SPOKE_PAID      VARCHAR2(100 BYTE),
      SPOKE_SEC       NUMBER,
      LAST_HELD_DATE  DATE,
      PREV_HELD_DATE  DATE,
      HUB_PAID        VARCHAR2(100 BYTE),
      HUB_SEC         NUMBER

    Hi,
    one suggestion. Don't include schema in the table.
    I have created your tables in my db with the following names:
    a_secmaster_dtl_ext_hst_tbl
    b_secmaster_detail_ext_hist
    spoke_to_hub_sec_mtch_tbl
    You query may be solved in this way maybe, according to what I have understood in the previous post.
    with table_a as
       select a.security_alias
            , c.spoke_paid
            , c.hub_paid
            , a.effective_date
         from a_secmaster_dtl_ext_hst_tbl  a
              join spoke_to_hub_sec_mtch_tbl c
                 on (a.security_alias=c.spoke_sec)
        where a.src_intfc_inst = 140
          and a.effective_date = (select max(a2.effective_date)
                                    from a_secmaster_dtl_ext_hst_tbl a2
                                   where a.security_alias=a2.security_alias
                                     and a.src_intfc_inst=a2.src_intfc_inst)
    , table_b as
       select b.security_alias
            , c.spoke_paid
            , c.hub_paid
            , b.effective_date
         from b_secmaster_detail_ext_hist  b
              join spoke_to_hub_sec_mtch_tbl c
                 on (b.security_alias=c.hub_sec)
        where b.src_intfc_inst = 140
          and b.effective_date = (select max(b2.effective_date)
                                    from b_secmaster_detail_ext_hist b2
                                   where b.security_alias=b2.security_alias
                                     and b.src_intfc_inst=b2.src_intfc_inst)
    select b.security_alias
         , a.spoke_paid
         , a.security_alias
         , b.hub_paid
         , 'SECMASTER_DETAIL_EXT_HIST' txt1
         , 'EFFECTIVE_DATE'            txt2
         , nvl(to_char(b.effective_date,'dd-mon-yyyy'), 'No Records Found') b_eff_date
         , nvl(to_char(a.effective_date,'dd-mon-yyyy'), 'No Records Found') a_eff_date   
      from table_a a full outer join table_b b on(a.spoke_paid=b.hub_paid)
    where a.effective_date!=b.effective_date;
    I have used full outer join to join the table to cover the case where records are present in table a and not in table b and the opposite.
    Regards.
    Alberto

  • Select query is correct or not

    hai to all iam software trainee in core java
    i have doubt on select query please give gudiance
    select * from StudentDetails where Admnno=' "
    i connected my application with ms-access db using jdbc-odbc
    my question is i want retrieve data from ms-access so i use this select query is it correct or not
    because
    select * from StudentDetails this query working but it's working with where condition please help and try to understand my question
    In advanced
    thanks

    ("select * from StudentDetails where Admnno ='' "+Admnno+"'")Is Admnno a numeric or character field? Either way, that syntax looks wonky.
    For a numeric field:("select * from StudentDetails where Admnno = " + Admnno)and for a character field("select * from StudentDetails where Admnno = '" + Admnno + "'")db
    Use code tags to post codes -- [code]CODE[/code] will display asCODEOr click the CODE button and paste your code between the tags that appear.

  • Doubt In a Select Query..

    Hi..
    I have a Doubt in a simple Query from the table NAST.
    My query is as follows:--
    Select kappl
           objky
           kschl
           parnr
           parvw
           nacha
           vsztp
    from nast into table vit_nast
    where kappl =   p_kappl
    and   kschl in s_kschl
    and   parnr in s_parnr
    and   nacha =   p_nacha
    and   vsztp in s_vsztp.
    Now I want to select all the NAST records which are either not processed (NAST-VSTAT = 0) or incompletely processed (NAST-VSTAT = 2)(the field in the table NAST is VSTAT which denotes the Processing status of message)
    So Can I add both the conditions in the WHERE clause of the the above Select Query?
    Is there any other optimised way I can do that?
    Thanks

    ranges: r_stat for nast-vstat.
    r_stat-low = '0'.
    r_stat-option = 'EQ'.
    r_stat-sign = 'I'.
    append r_stat.
    clear r_stat.
    r_stat-low = '2'.
    r_stat-option = 'EQ'.
    r_stat-sign = 'I'.
    append r_stat.
    clear r_stat.
    Select kappl
    objky
    kschl
    parnr
    parvw
    nacha
    vsztp
    from nast into table vit_nast
    where kappl = p_kappl
    and kschl in s_kschl
    and parnr in s_parnr
    and nacha = p_nacha
    and vsztp in s_vsztp
    <b>and vstat in r_stat.</b>
    check this..
    Regards
    vijay

  • Select query doubt

    hello all,
    i am writting this code .....first select is working fine for me as i am getting 5 entires in  table itab which i am expecting...
    but for second when i loop itab itab then at that time i should get one record  in table itab2 out of second select query........
    but as i can see while debugging  i am getting that entry at third time when i am in loop.....but it again i think it overwrites with next enter and making itab2 entry as 0 at the end.....
    what might be problem.
    even i write append itab2.
                        clear itab2.
    same error i am getting...(here CDPOS is cluster table..is this because of this??)..pease help
    selection-screen:begin of block test with frame title new.
    select-options: s_ddate for vbak-vdatu.
    selection-screen:end of block test.
    select avbeln avdatu bnetpr bnetwr b~matnr into corresponding fields of table itab
        from vbak as a inner join vbap as b on avbeln = bvbeln where
           b~matnr = 'AUP-501'
        and a~vdatu in s_ddate.
    LOOP AT ITAB.
    select *  from CDPOS into table itab2 where
      OBJECTID = ITAB-VBELN AND
      TABNAME = 'VBAP' AND
      FNAME = 'NETPR'.
    ENDLOOP.

    Hi,
    You are completely into wrong performance..
    as per your query
    selection-screen:begin of block test with frame title new.
    select-options: s_ddate for vbak-vdatu.
    selection-screen:end of block test.
    select avbeln avdatu bnetpr bnetwr b~matnr into corresponding fields of table itab
    from vbak as a inner join vbap as b on avbeln = bvbeln where
    b~matnr = 'AUP-501'
    and a~vdatu in s_ddate.
    LOOP AT ITAB.
    select * from CDPOS into table itab2 where
    OBJECTID = ITAB-VBELN AND
    TABNAME = 'VBAP' AND
    FNAME = 'NETPR'.
    ENDLOOP.
    The second query is inside loop and its moving data into itab2 for every record in internnale table ITAB and
    finally itab2 contains the last records of ITAB data if CDPOs has the data for itab-vbeln(last records).
    To over come you need to write the select as beloew
    select * from CDPOS APPENDING table itab2 where
    OBJECTID = ITAB-VBELN AND
    TABNAME = 'VBAP' AND
    FNAME = 'NETPR'.
    But I suggest you to write for all entries
    select <the filed you need> from CDPOS
    into table itab2
    for all entries in itab
    where OBJECTID = ITAB-VBELN AND
    TABNAME = 'VBAP' AND FNAME = 'NETPR'.
    Then
    loop at ITAB.
    Read table itab2 with key vbeln = itab-vbeln binary search.
    If sy-subrc = 0.
    <Write your code, functions etc>.
    endif.
    endloop.
    regards,
    Nazeer

  • Select query in case of Multiple line items

    Hi Gurus ,
                  I've a doubt in general SQL select query. I want to know , if suppose I've an internal table - itab . I've fetched G/L Account numbers 1st, based on the input selections . Next , I want to loop on those G/L accounts. However, if the G/L account has multiple line items, then I personally use this select query -- >
    loop at itab.
    select <field> from <table> appending corresponding fields of  <itab1> where hkont eq itab-hkont.
    endloop.
    Now, the execution time for this query is longer than expected. The biggest problem here is, i've to sum up the totals as well. So totaling is an added load. I want to reduce the execution time of this. Kindly suggest me some good method in case u have any.
    I've pasted the code which I've written , for u ppl to understand--
    SELECT DISTINCT HKONT BELNR
      FROM BSIS
       INTO CORRESPONDING FIELDS OF TABLE OTAB
        WHERE HKONT IN S_RACCT
    *      AND PRCTR IN P_PRCTR
          AND MONAT IN S_POPER
          AND BUKRS EQ P_BUKRS
          AND GJAHR EQ P_GJAHR
          AND PRCTR IN S_PRCTR.
    ***The code below takes a lot of time to execute.***
    LOOP AT OTAB .
      SELECT DMBTR HKONT
      FROM BSIS APPENDING CORRESPONDING FIELDS OF TABLE CREDITS
        WHERE HKONT EQ OTAB-HKONT
          AND BELNR EQ OTAB-BELNR
          AND MONAT IN S_POPER
          AND BUKRS EQ P_BUKRS
          AND GJAHR EQ P_GJAHR
          AND PRCTR IN S_PRCTR
          AND SHKZG EQ 'H'.
      COLLECT CREDITS.
    ENDLOOP.

    Hi,
    First of all try to avoid doing select into corresponding fields. THis would improve the performance of the program.
    Try to do a single fetch from the BSIS table . fetch the hkont, belnr, dmbtr fields in to a master internal table. Manipulate and play with the data as required.  Don't hit the data base table more than once (unless it is required) . This would improve the performance of your code.
    Try to code this way.
    types: begin of ty_bsis,
                 hkont type hkont,
                 belnr type  belnr_d,
                 dmbtr type dmbtr,
              end of ty_bsis.
    data: it_bsis type standard table of ty_bsis,
             wa_bsis type ty_bsis,
    select hkont belnr dmbtr
              from bsis
              into table it_bsis
              WHERE HKONT IN S_RACCT
            AND PRCTR IN P_PRCTR
              AND MONAT IN S_POPER
             AND BUKRS EQ P_BUKRS
             AND GJAHR EQ P_GJAHR
              AND PRCTR IN S_PRCTR.
    Using the data availabe in the it_bsis, you can manipulate as required.
    Hope this would be helpful
    Regards
    Ramesh Sundaram

  • Select query written on view giving dump

    Hi All,
    I have written the following query on COAS view in my code:
          SELECT aufnr bukrs INTO TABLE gt_aufnr
            FROM coas
              WHERE
                    aufnr IN r_aufrm AND
                    auart IN s_auart AND
                    autyp = c_autyp_01 AND
                    kokrs = c_kokrs_mbca.
    When records in range r_aufrm are too many like 6000 or so it gives me a run time error on this query - DBIF_RSQL_INVALID_RSQL. Error description says size of select query is large.
    Question : Is this bug coming because I am using the view. If i select the records on table AUFK (only table on which the view is created), will it rectify the problem?? I am asking this because it's in production and I cant make any change and test then and there.
    Note: the range r_aufrm contains two types of records for AUFNR - 1. with sign GE and others with sign LE. So I cannot use for all entries. If I still can, please tell me how?
    Thanks a looot!
    Waiting for the response,
    Navita

    Thanks All!!
    I think, this range limit has caused the problem. Range limit is 999 records.
    Just one question I have. At runtime when I check the number of entries in r_aufrm in the query, I get 6000 entries. So, does it allow 6000 records to enter the range variable even if it has a limit of 999. Is it the case that, in select query only it will throw a dump if records in range exceed 999??
    SELECT aufnr bukrs INTO TABLE gt_aufnr
    FROM coas
    WHERE
    aufnr IN r_aufrm AND
    auart IN s_auart AND
    autyp = c_autyp_01 AND
    kokrs = c_kokrs_mbca.
    Please clear my doubt.
    Thanks a lot for ur help!!!!
    Navita

  • Passing parameters to select query in DB link from invoke...

    I am having a DB partner link which executes the select query based on user specified parameter.
    Now i have created an invoke activity and specified input[this needs to be passed to query] and output parameters[this is query result]. This invoke activity calls DB partner link in which one parameter has been created to be used in select query. So my doubt is , will DB partner link take up the input parameter of invoke activity automatically or do we need to specify any mapping for this?

    When you create a db partnerlink the parameter you create for your select is the input and when you create the input variable in the invoke for this partnerlink it is created with the right type for the parameter.
    Create an Assign before your invoke and assign a value to the input variable you created in the invoke. That value will be passed and used as the parameter in the select.
    Heidi.

  • Doubt in sql query

    hi frs,
    i have a doubt in sql query.
    this is my query
    select * from scott.emp where comm like '3%'it will fetch all the values starting with 3.
    2nd query
    select * from scott.emp where comm like '%'this will give all the values except null. but i want to get null values also.how can i get i have used following query
    select * from scott.emp where comm like '%' or comm is not nullits working whether there is an any other option.because i am going to use similar kind of condition in my report query if iam going to use or in where condition it will affect the performance.
    pls help
    regards
    Rajesh

    Hi Rajesh,
    I'm sure I do not understand your requirement correctly.
    You say you want to retrieve rows that have or have not null in colum 'comm', right?
    If so, simply get rid of this part of your where clause (provided you have more conditions).
    select * from scott.emp shall be enough.
    Cheers,
    Guido

  • Doubt in forming Query

    Hi,
    I have a doubt in forming query.
    I have a table like this
    Inst_Id port1 sid port2
    1 2300 1 2302
    2 2304 1 2302
    3 2306 1
    4 2300 2
    5 2306 2 2308
    I need a result as for sid = 1(should take union of both port and list out with instd_id)
    Port Inst_Id
    2300 1
    2302 1
    2304 2
    2306 3
    Can any one help to get a query?
    -haifriends

    You simply answer:
    select inst_id,port1 from t where sid=1
    union
    select inst_id,port2 from t where sid=1

  • Parenthesis within a select query.

    I have a doubt as whether i can include Parenthesis within a select query
    as below:-
    SELECT C.CITY_CODE,A.DOCUMENT_TYPE,SUM(A.INSTRUMENT_AMounT) FROM
    ppbs_RECEIPT_HEADER A,ppbs_DISTRIBUTOR_MASTER C WHERE
    A.DISTRIBUTOR_ID = C.DISTRIBUTOR_ID AND
    ( A.STATUS not in( 'CN','BO') or (A.STATUS ='CN' and a.INSTRUMENT_AMOUNT<>a.UNAPPLIED_AMOUNT))
    as we do in a If condition. Please help in solving the doubt as it is urgent.

    No, the result is correct, but is it correct to put the parenthesises around a condition in a normal select query as we do in a 'if' condition or a sub-query. Will the condition in the query be evaluated first and then the other conditions in the normal select query.

  • Select query is not executing

    Hi Friends,
    my code is :
    itab-vbeln = bseg-vbeln.
    if not itab-vbeln is initial.
    select single vbeln inco1 inco2 into ( itab-vbeln itab-inco1 itab-inco2)
    from vbrk where vbeln = itab-vbeln.
    appned itab.
    note : here inco1 inco2 are incoterms
    my question is  can we direct move the values of bseg-vbeln into itab-vbeln. ???
    and i am generating the report with one varient , when i debug this report the
    there is no value in bseg-vbeln. it is showing null value.thats why my select query is not working..but i want execute this select query final.
    in output i want display the inco1 inco2 data.(incoterms)
    any help please.
    urgent.
    regards,
    vijay.

    Hi Vijay,
    First you need to check it out whether <b>itab-vbeln = bseg-vbeln</b> is in with in LOOP or not (<b>if ITAB is intenal table</b>)
    if itab is internal table you should write above statement with in loop, and also check it out in debug mode why bseg-vbeln value is not coming.
    and one more thing you need to make small correction in ur code use ',' .
    select single vbeln inco1 inco2 into ( <b>itab-vbeln, itab-inco1, itab-inco2</b>)
    from vbrk where vbeln = itab-vbeln
    Note: when ever use select single u should pass values into work area, dont use internal table .
    <b>if you have more doubts just send your entire code then i will rewrite it.</b>
    <b>Reward with points if useful.</b>
    Regards,
    Vijay Krishna

  • Long Time for execution of select query

    Hi,
    I have a select query
    select * from Table where Time1 and time 2;
    The table has a large no. of colums than rows. So the query taking a lot of time to execute.
    Is there any way we can reduce the time taken by the query.
    Thanks
    Jit
    Message was edited by:
    user637843

    select * from Table where Time1 and time 2;I doubt this query run for long time. More or less 1 millsecond, the time for Oracle to check the query syntax and return errors.
    Nicolas.

Maybe you are looking for

  • GR/IR with FI data in FAGL_FC_VAL

    Hi experts, What is the meaning of the checkbox: GR/IR with FI data in T-COD: FAGL_FC_VAL? There is no F1 documentation on this. Pls help. Thanks, Betty

  • Spatial Index and XA transaction

    Hi all, I have problem with spatial index in XA transaction. java.sql.SQLException: ORA-29875: failed in the execution of the ODCIINDEXINSERT routine ORA-29400: data cartridge error ORA-14450: attempt to access a transactional temp table already in u

  • Issue when implementing file download in OAF

    Hi, We are trying to download some data and create a excel file in the click of a button in the OAF screen. And the requirement is to navigate to the previous screen automatically after the file download. I have used pageContext.forwardImmediately()

  • How to get ATTENDEE, ORGANIZER, Respond Status on a Appointment?

    Hi I am using the Calendar SDK to view the appointments. When I use fetchEventsByRange or fetchEventsByID method, I am getting only few parameters like DTSTAMP, CATEGORIES, CLASS, PRIORITY, STATUS, DESCRIPTION, LOCATION, DTEND, SUMMARY, DTSTART, UID.

  • Mega BPM & Oracle BPM Integration

    is it possible to integrate Mega BPM Process into Oracle BPM? Can we have any connectors or xmg file import function in Oracle BPM?