I need a select query

I have a dataset like below in two columns ( col1,col2 in table Mytable)
A | ab
A | cd
A | ef
B | xl
B | ik
E | 23
E | op
C | tk
I need a select query which will return first set of every group which I ask for .
For example, if I ask for data for A , B , the select query will return records
A | ab
B | xl
For example, if I ask for data for B ,E the select query will return records..
B | xl
E | 23
For example, if I ask for data for C the select query will return records..
C | tk
How do I write my select query ?

Something like this ?
SCOTT@orcl> create table test(col1 varchar2(1),col2 varchar2(2));
Table created.
SCOTT@orcl> insert into test values('A','ab');
1 row created.
SCOTT@orcl> insert into test values('A','cd');
1 row created.
SCOTT@orcl> insert into test values('A','ef');
1 row created.
SCOTT@orcl> insert into test values('B','xl');
1 row created.
SCOTT@orcl> insert into test values('B','ik');
1 row created.
SCOTT@orcl> insert into test values('E','23');
1 row created.
SCOTT@orcl> insert into test values('E','op');
1 row created.
SCOTT@orcl> insert into test values('C','tk');
1 row created.
SCOTT@orcl> commit;
Commit complete.
SCOTT@orcl>
SCOTT@orcl> ed
Wrote file afiedt.buf
  1  select * from (
  2  select decode(lag(col1) over (order by col1,rownum),null,col1
  3  ,col1,null
  4  ,col1) col1
  5  ,col2
  6  from test) aaa
  7* where aaa.col1='A'
SCOTT@orcl> /
C CO
A abHTH
Girish Sharma

Similar Messages

  • Help needed in select query

    Hi,
    I need to select the max time for the transaction using the below query. I’m able to get the o/p. Here the problem is I need to fetch the corrletorid (primary key) as well. if try to get that I’m getting the o/p like case2.
    I want the o/p to be like case 1 with the corrleator id . plz help me to get the o/p.
    Case 1: select b.TransactionName, max(to_char(b.duration, 'mm/dd/yyyy hh24:mi:ss.ff')) as average from trandetails a,subtrandetails b where a.CORRELATORID=b.PCORRELATORID and b.PCORRELATORID='11' group by b.transactionname
    TRANSACTIONNAME MAXTIME
    FINT3 12/10/2007 19:53:09.042000
    FINT 12/10/2007 19:31:07.042000
    FINT2 12/10/2007 19:31:07.042000
    SQL> /
    Case 2: select b.TransactionName,b.correlatorid, max(to_char(b.duration, 'mm/dd/yyyy hh24:mi:ss.ff')) as average from trandetails a,subtrandetails b where a.CORRELATORID=b.PCORRELATORID and b.PCORRELATORID='11' group by b.transactionname,b.correlatorid
    SQL> /
    TRANSACTIONNAME CORRELATORID AVERAGE
    FINT2 102 12/10/2007 19:31:07.042000
    FINT3 108 12/10/2007 19:53:09.042000
    FINT3 103 12/10/2007 19:31:07.042000
    FINT 101 12/10/2007 19:31:07.042000
    in the above output i should have only record(max time) for FINT3.
    Thank

    Sharma,
    Please find the below sample data(insert stmt and create table):
    ======================================
    create table trandetails(
    correlatorid varchar2(20) CONSTRAINT correlatorid_FKey REFERENCES Subtrandetails(correlatorid),
    username varchar2(25) NOT NULL,
    applicationname varchar2(25) NOT NULL,CONSTRAINT composite1_pkey1 PRIMARY KEY(correlatorid ,applicationname));
    create table Subtrandetails(
    correlatorid varchar2(20) PRIMARY KEY,
    PCORRELATORID      varchar2(20),
    TransactionName varchar2(25) NOT NULL,
    Machinename varchar2(15) NOT NULL,
    STARTDATE timestamp NOT NULL,
    ENDDATE timestamp NOT NULL,
    SourceName varchar2(25),
    FunctionName varchar2(25),
    LOC number(5),
    CONTEXTPROPERTY1 varchar2(25),
    CONTEXTPROPERTY2 varchar2(25),
    CONTEXTPROPERTY3 varchar2(25),
    TransactionStatus varchar2(25) NOT NULL CONSTRAINT Transaction1_Status_chk Check (TransactionStatus in ('Success', 'Failure', 'Abort')));
    INSERT INTO trandetails VALUES ('11','FINAPP','ANUAPP1');
    INSERT INTO trandetails VALUES ('13','FINTEST','ANUAPP2');
    INSERT INTO
    Subtrandetails(correlatorid,PCORRELATORID ,TransactionName,Machinename,STARTDATE,ENDDATE ,TransactionStatus )
    VALUES ('10','1','ARM','blrkec95931d','10-DEC-07 03.24.07.042000 PM','10-DEC-07 03.31.07.042000 PM','Success');
    INSERT INTO
    Subtrandetails(correlatorid,PCORRELATORID ,TransactionName,Machinename,STARTDATE,ENDDATE ,TransactionStatus )
    VALUES ('11','1','ARM1','blrkec95931d','10-DEC-07 04.24.07.042000 PM','10-DEC-07 04.31.07.042000 PM','Success');
    INSERT INTO
    Subtrandetails(correlatorid,PCORRELATORID ,TransactionName,Machinename,STARTDATE,ENDDATE ,TransactionStatus )
    VALUES ('12','1','ARM2','blrkec95931d','10-DEC-07 05.24.07.042000 PM','10-DEC-07 05.31.07.042000 PM','Success');
    INSERT INTO
    Subtrandetails(correlatorid,PCORRELATORID ,TransactionName,Machinename,STARTDATE,ENDDATE ,TransactionStatus )
    VALUES ('13','1','ARM3','blrkec95931d','10-DEC-07 06.24.07.042000 PM','10-DEC-07 06.31.07.042000 PM','Success');
    INSERT INTO
    Subtrandetails(correlatorid,PCORRELATORID ,TransactionName,Machinename,STARTDATE,ENDDATE ,TransactionStatus )
    VALUES ('14','1','ARM4','blrkec95931d','10-DEC-07 07.24.07.042000 PM','10-DEC-07 07.31.07.042000 PM','Success');
    INSERT INTO
    Subtrandetails(correlatorid,PCORRELATORID ,TransactionName,Machinename,STARTDATE,ENDDATE ,TransactionStatus )
    VALUES ('101','11','FINT','blrkec95931d','10-DEC-07 07.24.07.042000 PM','10-DEC-07 07.31.07.042000 PM','Success');
    INSERT INTO
    Subtrandetails(correlatorid,PCORRELATORID ,TransactionName,Machinename,STARTDATE,ENDDATE ,TransactionStatus )
    VALUES ('102','11','FINT2','blrkec95931d','10-DEC-07 07.24.07.042000 PM','10-DEC-07 07.31.07.042000 PM','Success');
    INSERT INTO
    Subtrandetails(correlatorid,PCORRELATORID ,TransactionName,Machinename,STARTDATE,ENDDATE ,TransactionStatus )
    VALUES ('103','11','FINT3','blrkec95931d','10-DEC-07 07.24.07.042000 PM','10-DEC-07 07.31.07.042000 PM','Success');
    INSERT INTO
    Subtrandetails(correlatorid,PCORRELATORID ,TransactionName,Machinename,STARTDATE,ENDDATE ,TransactionStatus )
    VALUES ('104','13','SAP1','blrkec95931d','10-DEC-07 07.24.07.042000 PM','10-DEC-07 07.31.07.042000 PM','Success');
    INSERT INTO
    Subtrandetails(correlatorid,PCORRELATORID,TransactionName,Machinename,STARTDATE,ENDDATE ,TransactionStatus )
    VALUES ('105','13','SAP2','blrkec95931d','10-DEC-07 07.24.07.042000 PM','10-DEC-07 07.31.07.042000 PM','Success');
    INSERT INTO
    Subtrandetails(correlatorid,PCORRELATORID ,TransactionName,Machinename,STARTDATE,ENDDATE ,TransactionStatus )
    VALUES ('106','13','SAP3','blrkec95931d','10-DEC-07 07.24.07.042000 PM','10-DEC-07 07.31.07.042000 PM','Success');
    INSERT INTO
    Subtrandetails(correlatorid,PCORRELATORID ,TransactionName,Machinename,STARTDATE,ENDDATE ,TransactionStatus )
    VALUES ('107','13','SAP2','blrkec95931d','10-DEC-07 07.2.10.042350 PM','10-DEC-07 07.50.10.042050 PM','Success');
    INSERT INTO
    Subtrandetails(correlatorid,PCORRELATORID ,TransactionName,Machinename,STARTDATE,ENDDATE ,TransactionStatus )
    VALUES ('108','11',' FINT3 ','blrkec95931d','10-DEC-07 07.16.07.042000 PM','10-DEC-07 07.53.09.042000 PM','Success');
    INSERT INTO
    Subtrandetails(correlatorid,PCORRELATORID ,TransactionName,Machinename,STARTDATE,ENDDATE ,TransactionStatus )
    VALUES ('109','108','FINT3','blrkec95931d','10-DEC-07 07.20.07.042000 PM','10-DEC-07 07.59.09.042000 PM','Success');
    INSERT INTO
    Subtrandetails(correlatorid,PCORRELATORID ,TransactionName,Machinename,STARTDATE,ENDDATE ,TransactionStatus )
    VALUES ('110','108','FINT3','blrkec95931d','10-DEC-07 07.18.07.042000 PM','10-DEC-07 07.57.09.042000 PM','Success');
    INSERT INTO
    Subtrandetails(correlatorid,PCORRELATORID ,TransactionName,Machinename,STARTDATE,ENDDATE ,TransactionStatus )
    VALUES ('111','108','FINT4','blrkec95931d','10-DEC-07 07.18.07.042000 PM','10-DEC-07 07.57.09.042000 PM','Success');
    INSERT INTO
    Subtrandetails(correlatorid,PCORRELATORID ,TransactionName,Machinename,STARTDATE,ENDDATE ,TransactionStatus )
    VALUES ('112','108','FINT5','blrkec95931d','10-DEC-07 07.18.07.042000 PM','10-DEC-07 07.57.09.042000 PM','Success');
    INSERT INTO
    Subtrandetails(correlatorid,PCORRELATORID ,TransactionName,Machinename,STARTDATE,ENDDATE ,TransactionStatus )
    VALUES ('113','108','FINT6','blrkec95931d','10-DEC-07 07.18.07.042000 PM','10-DEC-07 07.57.09.042000 PM','Success');
    INSERT INTO
    Subtrandetails(correlatorid,PCORRELATORID ,TransactionName,Machinename,STARTDATE,ENDDATE ,TransactionStatus )
    VALUES ('114','108','FINT7','blrkec95931d','10-DEC-07 07.18.07.042000 PM','10-DEC-07 07.57.09.042000 PM','Success');
    ======================================
    Thanks.

  • Help need in selection query

    Hi ,
    I have a field(test) in ztable(zxxx) whose length is 12 char and while updating it
    only 10 digits were updated and there are no zeros in front of the value in order to make it
    12 digit.
    Now i need this parameter to be included in another program selection screen.
    Now i have given it as
    parameter :  test(12) type n.
    it works fine when it has an entry , when it is blank i has to retrieve all records but in this case
    i won't because it has a value of 000000000000
    noe when i declare like this
    paramter : test like zxxx-test.
    when my input is 123456, it won't fetch me any value because it has to be 0000123456 because it has been updated like in the table.
    There was a purpose in updating this way.
    Now my code is like this
    parameters : test(10) type n.
    select-options :   kostl for zxxx-kostl NO-EXTENSION NO INTERVALS,
          p_uname for zxxx-uname NO-EXTENSION NO INTERVALS.
    if test is initial.
    select * from zxxx into table itab where kostl in kostl and uname in p_uname.
    else.
    select * from zxxx into table itab where aufnr  = order and
                                   kostl in kostl and uname in p_uname.
    endif
    PLEASE SUGGEST ME IF THERE IS AN ALTERNATE BETTER WAY.
    or this is the best way
    Thanks

    Hi
    as per my knowledge what you have done is right.
    Thanks
    KAJOL

  • Help needed in select query to take date

    Hello,
    I am using Oracle 11g.
    I am using this query
    select to_date(to_char(to_date((SOURCE_MONTH||'-'||SOURCE_YEAR),'MM-YYYY'),'Mon-YYYY'),'MON-YYYY') date_
    from tab1 a,tab2 b
    where b.col2=a.col1;
    I have a table with 2 separate varchar columns month and year,
    I want to insert the data into another table which has the col type as timestamp.
    This query gives me the data as
    01-NOV-06 but
    i want the data as
    01-NOV-2006
    What should i do for that?
    Thanks

    First, get rid of the extra conversions from date to char and back to date:
    select to_date((SOURCE_MONTH||'-'||SOURCE_YEAR),'MM-YYYY'),'Mon-YYYY')
    from tab1 a,tab2 b
    where b.col2=a.col1;Now, your data is safely rendered as a DATE. It knows the full year (i.e.2006). You are just not seeing it formatted the way you like. You could
    alter session set nls_date_format = 'mm/dd/yyyy hh24:mi:ss';or give the explicit format you want when you query it (with TO_CHAR).
    Please read and understand about DATE datatypes....
    http://download.oracle.com/docs/cd/B28359_01/server.111/b28286/sql_elements001.htm#i54330
    In particular, search that page for: "DATE Datatype "

  • Select Query Between two dates...

    Hi Guru's,
    I need a Select Query between two dates, also if the record not found for any in between date then it should return NULL or 0 ...
    for Example
    1. I am having two records in DB for date 2-10-2008 & 4-10-2008
    2. Now suppose I have given Query for date between 1-10-2008 to 5-10-2008
    Then it should return me 5 records with valid values for 2 & 4 and NULL for other 1,3,5
    Thanks.

    Try like this:
    with
      t as
          select date '2008-10-02' as dt, 'Record #1 (in DB)' as str from dual union all
          select date '2008-10-04' as dt, 'Record #2 (in DB)' as str from dual
    select v.dt, t.str
      from (
             select date '2008-10-01' + level - 1 as dt
               from dual
             connect by level <= (date '2008-10-05' - date '2008-10-01') + 1
           ) v
      left join t
        on v.dt = t.dt
    order by 1

  • Regading Select query for Inspection planed date

    Hi,
       I am working on one object.I need to select query to get the inspection plan valid from date(PLKO-DATUV).Logic is Find the group counter(QALS-PLNNR),Group counter(QALS_PLNAL) based on materail(SELMATNR) & BATCH(CHARG) and get the inspection plan valid from date(PLKO-DATUV).How to write the select performance wise.Please help me.
    Regards,
    Sujan

    hi Kat,
    do this way ..
    data : v_date like ekko-aedat value '20080424'.
    select ebeln
    bsart
    aedat
    ernam
    lifnr
    from ekko
    into table it_ekko
    where
    *ebeln eq ekko-ebeln
    and aedat gt v_date
    and bsart 'AN'
    and ( frggr is null or
            frgsx is null or
            frgke eq '1' ) .
    Regards,
    santosh

  • Convert columns to rows by a select query

    I have a table with 10 columns. Pk is combination of 3 columns, let us say A, B and C. I need a select query which returns 7 rows with four columns each let us say A,B,C and D where D contains the value of non PK column. i.e. for first row, D will contain value of fourth column of the table, for second row, D will contain fifth column of the table and so on.
    Please help.

    Maybe NOT TESTED!
    select col_a,col_b,col_c,column_4 col_d
      from (select col_a,col_b,col_c,col_d,col_e,col_f,col_g,col_h,col_i,col_j
              from the_table
    unpivot include nulls (column_4 for source_column in (col_d as 'col_d',
                                                          col_e as 'col_e',
                                                          col_f as 'col_f',
                                                          col_g as 'col_g',
                                                          col_h as 'col_h',
                                                          col_i as 'col_i',
                                                          col_j as 'col_j'
                          )Regards
    Etbin

  • Need help in writing a select query to pull required data from 3 tables.

    Hi,
    I have three tables EmpIDs,EmpRoles and LatestRoles. I need to write a select Query to get roles of all employees present in EmpIDs table by referring EmpRoles and LatestRoles.
    The condition is first look into table EmpRoles and if it has more than one entry for a particular Employee ID than only need to get the Role from LatestRoles other wise consider
    the role from EmpRoles .
    Sample Script:
    Create Table #EmpIDs
    (EmplID int )
    Create Table #EmpRoles
    (EMPID int,Designation varchar(50))
    Create Table #LatestRoles
    EmpID int,
    Designation varchar(50)
    Insert into #EmpIDs values (1),(2),(3)
    Insert into #EmpRoles values (1,'Role1'),(2,'Role1'),(2,'Role2'),(3,'Role1')
    Insert into #LatestRoles values (2,'Role2')
    Employee ID 2 is having two roles defined in EmpRoles so for EmpID 2 need to fetch Role from LatestRoles table and for
    remaining ID's need to fetch from EmpRoles .
    My Final Output of select query should be like below.
    EmpID Role
    1 Role1
    2 Role2
    3 Role1
    Please help.
    Mohan

    Mohan,
    Can you check if this answers your requirement:
    Create Table #EmpIDs
    (EmplID int )
    Create Table #EmpRoles
    (EMPID int,Designation varchar(50))
    Create Table #LatestRoles
    EmpID int,
    Designation varchar(50)
    Insert into #EmpIDs values (1)
    Insert into #EmpIDs values (2)
    Insert into #EmpIDs values (3)
    Insert into #EmpRoles values (1,'Role1')
    Insert into #EmpRoles values (2,'Role2')
    Insert into #EmpRoles values (2,'Role1')
    Insert into #EmpRoles values (3,'Role1')
    Insert into #LatestRoles values (2,'Role2')
    --Method 1
    select e.EmplID,MIN(ISNULL(l.Designation,r.Designation)) as Designation
    from #empids e
    left join #emproles r on e.emplID=r.EmpID
    left join #latestRoles l on e.emplID=l.EmpID
    group by e.EmplID
    --Method 2
    ;with cte
    as
    select distinct e.EmplID,r.Designation,count(*) over(partition by e.emplID) cnt
    from #empids e
    left join #emproles r on e.emplID=r.EmpID
    select emplID,Designation
    from cte
    where cnt=1
    UNION ALL
    select a.EmplID,l.Designation
    from
    (select distinct EmplID from cte where cnt>1) a
    join #Latestroles l on a.EmplID=l.EmpID
    order by emplID
    Thanks,
    Jay
    <If the post was helpful mark as 'Helpful' and if the post answered your query, mark as 'Answered'>

  • Need of SQL query in selecting distinct values from two tables

    hi,
    I need a query for selecting distinct values from two tables with one condition.
    for eg:
    there are two tables a & b.
    in table a there are values like age,sex,name,empno and in table b valuses are such as age,salary,DOJ,empno.
    here what i need is with the help of empno as unique field,i need to select distinct values from two tables (ie) except age.
    can anybody please help me.
    Thanks in advance,
    Ratheesh

    Not sure what you mean either, but perhaps this will start a dialog:
    SELECT DISTINCT a.empno,
                    a.name,
                    a.sex,
                    b.salary,
                    b.doj
    FROM    a,
            b
    WHERE   a.empno = b.empno;Greg

  • Needs  help to retrive the last row in a  select query without using rownum

    Hi ,
    i need to retrive the last row from the select sub query without using rownum.
    is there any other way to retrive the last row other than the below query.
    is that the ROWNUM=1 will always retrive the 1 row of the select query ?
    select from*
    *(select ename from employee where dept_id=5 order by desc) where rownum=1;*
    Please advise.
    thanks for your help advance,
    regards,
    Senthur

    957595 wrote:
    Actually my problem is ithat while selecting the parents hiearchy of the child data using
    CONNECT BY PRIOIR query
    I need the immediate parent of my child data.
    For example my connect BY query returns
    AAA --- ROOT
    BBB --PARENT -2
    CCC --PARENT-1
    DDD IS my input child to the connect by query
    Immediate parent of my child data "DDD" ---> CCC(parent -1)
    i want the data "CCC" from the select query,for that i am taking the last row of the query with rownum.
    I got to hear that using ROWNUM to retrive the data will leads to some problem.It is a like a magic number.I am not sure what the problem will be.
    So confusing with using this rownum in my query.
    Please advice!!!It's not quite clear what you're wanting, but perhaps this may help?
    you can select the PRIOR values to get the parent details if you want...
    SQL> ed
    Wrote file afiedt.buf
      1  select empno, lpad(' ',(level-1)*2,' ')||ename as ename, prior empno as mgr
      2  from emp
      3  connect by mgr = prior empno
      4* start with mgr is null
    SQL> /
         EMPNO ENAME                                 MGR
          7839 KING
          7566   JONES                              7839
          7788     SCOTT                            7566
          7876       ADAMS                          7788
          7902     FORD                             7566
          7369       SMITH                          7902
          7698   BLAKE                              7839
          7499     ALLEN                            7698
          7521     WARD                             7698
          7654     MARTIN                           7698
          7844     TURNER                           7698
          7900     JAMES                            7698
          7782   CLARK                              7839
          7934     MILLER                           7782
    14 rows selected.(ok, not the best of examples as the mgr is already known for a row, but it demonstrates you can select prior data)

  • Need Select  Query

    hi,
       Need Select  Query for this...
    12.     Check if the document category TVLK-VBTYP = ‘7’ where TVLK-LFART = LIKP-LFART (Delivery Type) then this is and Inbound Delivery for a purchase order.
    13.     Check the value of field Shipment External ID#1 (VTTK-EXTI1) is not initial then check the BOL Data Format. If not VICSBOL then set the variable LI_INBVICS = ‘N’. and  assign Shipment External ID#1 to Shipment External ID#2 i. e VTTK-EXTI2 = VTTK-EXTI1. and  Check the TMS  BOL Format. If VICSBOL then set LI_INBVICS = ‘Y’ .

    Hi,
    1)
    IF TVLK-VBTYP = ‘7’ and TVLK-LFART = LIKP-LFART.
    Inbound Is for a Purchase order.
    ELSE.
    Inbound Is not for a Purchase order.
    Endif.
    2)
    IF not VTTK-EXTI1 is initial.
    IF BOL DATA <> VICSBOL.
    LI_INBVICS = ‘N’.
    VTTK-EXTI2 = VTTK-EXTI1
    else if BOL DATA <> VICSBOL.
    LI_INBVICS = ‘Y’
    Endif.
    endif.
    endif.

  • I need to know the proper syntax for my SELECT query, please.

    Hello All,
    Quick one for you:
    Let's say that I have several columns in a table with names such as subject_1, subject_2, subject_3, etc. The table's name is subject_names.
    The number in each of the three column name examples is also a value passed along a query string, the user can select choices, 1, 2 or 3. That query string's variable is $qs.
    So, what I want is a SELECT query that uses the query string value as follows (KEEP IN MIND, I know this is not the proper syntax):
    "SELECT subject_[$qs]
    FROM subject_names";
    I have tried all sorts of cominations of quotes (single and double), dots, brackets, braces and parenthesis. I just want to know how to include such a variable within this code.
    Any and all help is sincerely appreciated!
    Cheers,
    wordman

    Well, I did give you the syntax though.
    $query = 'SELECT ' . $qs . ' FROM tbl_name';
    I put spaces between the periods this time to make it more clear.
    If you put the actual word 'subject' in there and just want your form to name it's options as the numbers available you could do this:
    $query = 'SELECT subject_' . $qs . ' FROM tbl_name';
    In PHP you can use either single or double quotes around your query string, I always just use single quotes. I see a lot of other use double quotes.
    Double quotes would look like:
    $query = "SELECT subject_' . $qs . ' FROM tbl_name";
    Or when using double quotes you can actually just place the variable right in the string without having to concatenate multiple strings like above.
    Since you mentioned that you are good with passing variables I probably don't have to mention that you need to set the value attribute of your option tags (if you are using a select) to the value you want them to pass.
    Ex:
    <select name="choices">
         <option value="1">1</option>
         <option value="2">2</option>
         <option value="3">3</option>
    </select>
    If you have that part all figured out then you can use the syntax above for your query string.
    Good luck.

  • I need to add a single field from with_item table . need to write select query with reference to company code , account doc no , fiscal year

    I need to add a single field from with_item table . need to write select query with reference to company code , account doc no , fiscal year

    Hi Arun ,
    Can you explain little bit more ??
    what is account doc no? 
    what are the transactions should be displayed in your output??
    -Rajesh N

  • Need some help with the Select query.

    Need some help with the Select query.
    I had created a Z table with the following fields :
    ZADS :
    MANDT
    VKORG
    ABGRU.
    I had written a select query as below :
    select single vkorg abgru from ZADS into it_rej.
    IT_REJ is a Work area:
    DATA : BEGIN OF IT_REJ,
            VKORG TYPE VBAK-VKORG,
            ABGRU TYPE VBAP-ABGRU,
           END OF IT_REJ.
    This is causing performance issue. They are asking me to include the where condition for this select query.
    What should be my select query here?
    Please suggest....
    Any suggestion will be apprecaiated!
    Regards,
    Developer

    Hello Everybody!
    Thank you for all your response!
    I had changes this work area into Internal table and changed the select query. PLease let me know if this causes any performance issues?
    I had created a Z table with the following fields :
    ZADS :
    MANDT
    VKORG
    ABGRU.
    I had written a select query as below :
    I had removed the select single and insted of using the Structure it_rej, I had changed it into Internal table 
    select vkorg abgru from ZADS into it_rej.
    Earlier :
    IT_REJ is a Work area:
    DATA : BEGIN OF IT_REJ,
    VKORG TYPE VBAK-VKORG,
    ABGRU TYPE VBAP-ABGRU,
    END OF IT_REJ.
    Now :
    DATA : BEGIN OF IT_REJ occurs 0,
    VKORG TYPE VBAK-VKORG,
    ABGRU TYPE VBAP-ABGRU,
    END OF IT_REJ.
    I guess this will fix the issue correct?
    PLease suggest!
    Regards,
    Developer.

  • SELECT query very slow, need suggestion.

    Dear all,
    Below stmt was coded in my report program.
    It was taking around 14 seconds in development system. The days in s_datum was just 1 or 2 days max.
    But when the same was transferred to test system, it is taking almost 10 minutes, though it we gave just 1 day.
      SELECT * FROM likp INTO TABLE i_likp                  
            WHERE erdat IN s_datum AND wadat_ist > '00000000' 
              AND lfart <> 'EL'                               
              AND vstel not in s_vstel.
    Some of you might suggest to make SELECT query with only s_datum, but i tried it in dev system, it was taking almost 22 secs with only s_datum.  I thought it could be more worse in test system so, did not move that idea.
    Can some one please suggest me why it is happening so.

    Hi,
    The difference, as I suppose you know, happens because LIKP probably has much more records in production than in the development system.
    You must think what is selective in your WHERE clause:
    - erdat in s_datum is selective if you are are only using one day
    - wadat_ist GE '00000000' is not selective (all deliveries with goods issue fulfill that condition)
    - lfart NE 'EL' probably is not selective
    - vsten not in s_vstel probably is not selective
    So in the end only erdat is selective. There is no index in LIKP by ERDAT, so if you really want to make it faster you would need an index by ERDAT.
    Still, if you are only making one SELECT (not inside a loop) I wouldn't expect that to take more than 10 minutes.
    I would measure the program with SE30 to make sure it is really the SELECT that is taking so much time (post here the results), and if it really is the select post here the explain plan.
    By the way, if you need to know all goods issues for the last day I would use change pointers instead.
    Hope this helps,
    Rui Dantas

Maybe you are looking for

  • How to create a new rate category

    hi, Could anyone please guide me how can i create a new rate category. Thanks and Regards Mahavir

  • Value in the place if Id

    Hi, I have a school.uix page and department.uix page.Department.uix contains a foreign key from school.uix. And the problem is , I want to show the school name instaed of foreigh key id in department.uix. Can someone tell me how can I achieve this. A

  • HT201441 I bought this ipad at a pawn shop and can't activate it please help

    I can not activate my IPad i bought from a pawn shop please help me

  • Moving around in space???

    Hi, I'm writting a CAD type program. I'm using UTM coordinates ranging between 50000 and 100000. Instead of transforming all my coordinates can I just set my local to be located in that area and use the actual UTM coordinates? If so, how do I create

  • LabView error code 1940

    I have created a LabView VI to take some Sound and Vibration toolkit measurements on a PXI-4461 card. I've created a .exe and a .dll out of the VI and both give me a 1940 error code (source = SVT Unit Conversion (Complex)(1 Ch).vi) the first time the