Inserts on Sub (minus) Query

Ok. This is what I need to complete. I need to Insert from a minus subquery.
Here is my query where I need to insert the results.
select id_user, system_id, nm_database, cd_altname from accounts_temp
minus
select id_user, system_id, nm_database, cd_altname from accounts
From the results, I need to insert all fields into 'Accounts'. Note, that the four columns listed above in the subquery, are only 4 of the 15 columns in the tables; I need to insert *. I cannot use a the merge on b/c sometimes, the values of these columns are null.
Any thoughts?

or more simple
insert into accounts
select * from accounts_temp
where (id_user, system_id, nm_database, cd_altname) not in
         (select (id_user, system_id, nm_database, cd_altname) from accounts)Although usually "not in" is not very fast. It could be replaced by "no exists" or compared for performance with the previous version.
Edited by: Sven W. on Oct 21, 2008 8:55 AM

Similar Messages

  • Single Sub Row Query Returns More Than 1 Row!

    I am trying to update values in a table from another table and getting the error: Single Sub Row Query Returns More Than 1 Row.
    I want table B's PRV_NAME updated into table A's PRV_NAME where A.PRVID = B.PRVID where B.PRV_TYPE = M'
    Both tables have all unique PRVID's, however, table B has PRVID's that have the same name. So table B data can look like this:
    PRVID PRV_NAME
    1234 PHOENIX MED
    1235 SAC MED
    1236 SAC MED
    1237 OVERLAND
    etc..
    So, as you can see the PRVID's are unique, but not the PRV_NAME's. Is this the reason why I get this error?
    I did not build the tables and have no control over what is put in them. If this is the reason for the error, is there any way to resolve this?
    For reference, here is the query. Maybe there is something wrong with this?
    update msb_prv_source ps
    set ps.prv_name =
    (select prv00.prv00_prv_name
    from prv00_prv prv00
    join msb_prv_source ps
    on prv00.prv00_prv_id = ps.prvid
    where prv00.prv00_prv_type = 'M')
    Edited by: user12296489 on Apr 19, 2013 10:46 AM

    Hi,
    user12296489 wrote:
    I am trying to update values in a table from another table and getting the error: Single Sub Row Query Returns More Than 1 Row. Post your code. It's hard to say what you're doing wrong when I don't know what you're doing.
    I want table B's PRV_NAME updated into table A's PRV_NAME where A.PRVID = B.PRVID
    Both tables have all unique PRVID's, however, table B has PRVID's that have the same name. So table B data can look like this:
    PRVIDIf b.prvid is really unique, then
    UPDATE  a
    SET     prv_name = (
                     SELECT  prv_name
                     FROM    b
                     WHERE   a.prvid     = b.prvid
    ;should work, whether the other columns are unique or not.
    (Depending on your data and your requirements, you might want to use MERGE rather than UPDATE).
    I hope this answers your question.
    If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all the tables involved, and the results you want from that data.
    In the case of a DML operation (such as UPDATE) the sample data should show what the tables are like before the DML, and the results will be the contents of the changed table(s) after the DML.
    Explain, using specific examples, how you get those results from that data.
    Always say what version of Oracle you're using (e.g. 11.2.0.2.0).
    See the forum FAQ {message:id=9360002}
    Edited by: Frank Kulash on Apr 19, 2013 2:00 PM
    I see you've posted your code now:
    update msb_prv_source ps
    set ps.prv_name =
    (select prv00.prv00_prv_name
    from prv00_prv prv00
    join msb_prv_source ps
    on prv00.prv00_prv_id = ps.prvid
    where prv00.prv00_prv_type = 'M')Even if ps.prvid is unique, the sub-query can return more than 1 row if prv00.prv00_prv_id is not unique. When that that's the case, what do you want to happen? Include examples when you post the sample data and desired results.

  • PLW-07204: conversion away from column type may result in sub-optimal query

    I have the following query in the package that created using sql developer. I am receiving the error 'PLW-07204: conversion away from column type may result in sub-optimal query plan' when try to compile the package. The issue is happen to be in the last line where the date is. Any help? Thanks
    select count(*) into n_cnt
    from tmp_order
    where sgn_off_dt is null and cmt_dt is not null
    and sysdate - cmt_dt > 90;

    Sy:
    Try doing as a procedure instead of an anonymous block. It looks like warnings do not apply to blocks.
    SQL> create table tmp_order(sgn_off_dt date,cmt_dt date);
    Table created.
    SQL> alter session set plsql_warnings='ENABLE:ALL';
    Session altered.
    SQL> create procedure p as
      2     n_cnt number;
      3  begin
      4     select count(*) into n_cnt
      5     from tmp_order
      6     where sgn_off_dt is null and
      7           cmt_dt is not null and
      8           sysdate - cmt_dt > 90;
      9  end;
    10  /
    SP2-0804: Procedure created with compilation warnings
    SQL> show err
    Errors for PROCEDURE P:
    LINE/COL ERROR
    8/18     PLW-07204: conversion away from column type may result in
             sub-optimal query planlindalop:
    In this case, you can ignore the warning, as it is not correct. Sysdate and a date column have different internal data types (note the type 13 for sysdate and type 12 for the date column), and whatever internally generates the warnings seems to just compare the type number.
    SQL> insert into tmp_order values(sysdate, sysdate);
    1 row created.
    SQL> commit;
    Commit complete.
    SQL> select dump(sysdate) sdate, dump(cmt_dt) cmt_dt from tmp_order;
    SDATE                             CMT_DT
    Typ=13 Len=8: 7,219,2,3,15,44,4,0 Typ=12 Len=7: 120,111,2,3,16,44,12However, Oracle is perfectly capable of using an index on a date column with sysdate as a predicate. I would agree with Sy's suggestion to re-work the predicate to be something like cmt_dt < sysdate - 90.
    John

  • WebI:Creating a minus query from data providers not using the same universe

    Hi there. A client of ours wishes to use Combined Query on multiple universes in the same WebI report. So far, I have heard it is not feasible in WebI. I know it is possible in DeskI. Even the sub-query option is limited to just one universe in WebI. So, I am stuck.
    Is there a workaround to creating a minus query from data providers not using the same universe in WebI?

    Hello Amit,
    what are the Datasources ? Usually when you create a Sub Query you can choose a seperate Universe.
    Maybe if you only see one Universe you only have the rights for this Universe ?!.
    Regards
    -Seb.

  • Need a procedure to make minus query as output for 2 tables

    Can anybody help me to create a procedure so that I could get minus query of 2 table as a result.
    Requirement:
    I have two table 1- src_table_list ,2- tgt_table_list both tables have 2 columns : serial_no,table_name and 100 records each. and details mentioned in column "table_name" are actually tables name which present in my testing database.
    so I need one procedure which will pick one table_name from src_table_list and one table_name from tgt_table_name each time recursively and provide minus query as a result. as below.
    select c1,c2,c3,c4 from table1 --(fetched from src_table_list)
    minus
    select b1,b2,b3,b4 from table2 --(fetched from tgt_table_list)
    Can any body give or help me to create the procedure..as I have to prepare minus query for more than 200 tables and then I need to test them for integration testing..
    Edited by: 974253 on Nov 30, 2012 5:39 AM

    select 'select '||chr(39)||src_table_list.tblname||chr(39)||','||chr(39)||trg_table_list.tblname||chr(39)||',count(*) from '||' ( select * from '||src_table_list.tblname||'minus select * from '||trg_table_list.tblname||');'
    from src_table_list, trg_table_list
    WHERE src_table_list.serial_no = tgt_table_list.serial_no
    The above statement should give output similar to below code and will list down all the table names in the 2 tables(i.e. above src and trg) -
    select 'src_table_list.tbl1','trg_table_list.tbl1',count(*) from
    (select col1, col2 from src_table_list.tbl1 minus select col1, col2 from trg_table_list.tbl1 );
    select 'src_table_list.tbl2','trg_table_list.tbl2',count(*) from
    (select col1, col2 from src_table_list.tbl2 minus select col1, col2 from trg_table_list.tbl2 );
    Now atleast you can run these statements as script and get to know what all tables are having count differences.
    I might have missed out on some syntax part in above code but hope to have helped you in some way as you will be specific with number of tables to check for differences.

  • Conversion away from column type may result in sub-optimal query plan

    Hello all,
    I have the following select statement in a cursor compiled in a package.
    SELECT id
    FROM table
    WHERE TRUNC(ts) >= TRUNC(SYSDATE - p_days)
    However I get 4 warnings that read:
    PLW-07204: conversion away from column type may result in sub-optimal query plan
    Does anyone know of a way to rewrite the query to avoid the compilation warnings?
    I'm just trying to compare the date without the time...
    Thanks in advance
    Dan

    For what it is worth, whenever you compare a date column to either sysdate or any built-in function returning a date you will get that warning.
    SQL> desc t
    Name                                      Null?    Type
    ID                                                 NUMBER
    DT                                                 DATE
    SQL> SELECT DUMP(dt), DUMP(trunc(dt)), dump(sysdate)
      2  FROM t;
    DUMP(DT)                            DUMP(TRUNC(DT))                  DUMP(SYSDATE)
    Typ=12 Len=7: 120,107,7,12,15,16,43 Typ=13 Len=8: 7,215,7,12,0,0,0,0 Typ=13 Len=8: 7,215,7,12,14,16,11,0But,
    SQL> CREATE FUNCTION f(p_v IN VARCHAR2) RETURN DATE AS
      2  BEGIN
      3     RETURN TO_DATE(p_v, 'dd-mon-yyyy');
      4  END;
      5  /
    Function created.
    SQL> SELECT DUMP(f('01-jan-2000')) FROM dual;
    DUMP(F('01-JAN-2000'))
    Typ=12 Len=7: 120,100,1,1,1,1,1John

  • How to insert autoincrement record and query it with multiple keys

    Hi all,
    I am not familiar with BerkeyleyDB, I am now doing a project that needs to insert records and then query it out with multiple keys at later time. Since there is no field that can be distinct primary key, I want to user DbSequence as auto increment primary key to db, and set other index keys as secondary db, then using join cursor to do query with multiple keys.
    I don't know how to use DbSequence, can anyone direct me to a example of using DbSequence as auto increment primary key?
    Regards
    -Bruce

    I figured out the method to insert record with auto increment primary key. I listed the code block below:
    char m_SeqNamePositions[32] = "MyPositions";
    DbSequence *m_pSeqPositions;
    m_pDBPositions = new Db(NULL, 0);
              m_pDBPositions->open(NULL, pszFileName, szFileName, DB_BTREE, DB_CREATE, 0);          // 无数据文件
              m_pSeqPositions = new DbSequence(m_pDBPositions, 0);
              Dbt key((void *)m_SeqNamePositions, (u_int32_t)strlen(m_SeqNamePositions));
              m_pSeqPositions->open(NULL, &key, DB_CREATE);
    db_seq_t SeqNum;
         m_pSeqPositions->get(0, 1, &SeqNum, 0);
         Dbt key((void *)&SeqNum, (u_int32_t)sizeof(SeqNum));
         Dbt data(pRecord, sizeof(*pRecord));
         return m_pDBPositions->put(NULL, &key, &data, DB_NOOVERWRITE);
    m_pSeqPositions->close(0);
              m_pDBPositions->close(0);
    delete m_pSeqPositions;
    delete m_pDBPositions;
              m_pDBPositions = NULL;

  • Minus query returning row

    Hi
    One of my sql minus query is returning row even though both the statements are having same value.
    My query is following :
    SELECT UNIQUE EMP_AGG_DW_PAYROLL_TOT_FTE_CNT,EMP_AGG_PAY_DEM_EMP_SKEY
    FROM DW.AGG_EMP_ACCT_COMPENSATIONS
    WHERE EMP_AGG_DW_EFF_START_DT='1-jan-2006'
    AND EMP_AGG_PAY_DEM_EMP_SKEY IN (133607,141955)
    MINUS
    select * from (
    SELECT SUM(CS),PAY_DEM_EMP_SKEY FROM (
    SELECT SUM(CP)/24 CS,PAY_DEM_EMP_SKEY FROM (
    SELECT COUNT(PAY_DEM_DW_PAYROLL_FTE_COUNT) CP,PAY_DEM_EMP_SKEY FROM
    DW.PAYROLL_DEMOGRAPHICS A,MRADMIN_PROFPROCDT MP
    WHERE PAY_DEM_DW_PAYROLL_FTE_COUNT=1
    AND PAY_DEM_DW_PAYROLL_ADJUST_IND = 0
    AND PAY_DEM_EMP_SKEY IN (133607,141955)
    AND (TRUNC(A.PAY_DEM_PAY_DT) BETWEEN TRUNC(MP.D_BEGIN_DATE)
    AND TRUNC(MP.D_END_DATE))
    GROUP BY PAY_DEM_EMP_SKEY)GROUP BY PAY_DEM_EMP_SKEY
    UNION ALL
    SELECT SUM(CP)/48 CS,PAY_DEM_EMP_SKEY FROM (
    SELECT COUNT(PAY_DEM_DW_PAYROLL_FTE_COUNT) CP,PAY_DEM_EMP_SKEY FROM DW.PAYROLL_DEMOGRAPHICS
    WHERE PAY_DEM_DW_PAYROLL_FTE_COUNT=.5
    AND PAY_DEM_DW_PAYROLL_ADJUST_IND = 0
    AND PAY_DEM_EMP_SKEY IN (133607,141955)
    GROUP BY PAY_DEM_EMP_SKEY)GROUP BY PAY_DEM_EMP_SKEY )
    GROUP BY PAY_DEM_EMP_SKEY
    This is returning two rows.
    When I run queries seperatly then i am getting following result :
    EMP_AGG_DW_PAYROLL_TOT_FTE_CNT     EMP_AGG_PAY_DEM_EMP_SKEY
    0.0416666666666667                133607
    0.0416666666666667                    141955
    SUM(CS)          PAY_DEM_EMP_SKEY
    0.0416666666666667 133607
    0.0416666666666667     141955
    I am unable to get the exact reason behind me.
    Any help is higly appreciated.

    Probably some differences that are not shown due to rounding as in example below?
    SQL> set numw 5
    SQL> select 1.666666666666 from dual;
    1.666666666666
             1,667
    Elapsed: 00:00:00.00
    SQL> select 1.666666 from dual;
    1.666666
       1,667
    Elapsed: 00:00:00.00
    SQL> select 1.666666666666 from dual
      2  minus
      3  select 1.666666 from dual;
    1.666666666666
             1,667
    Elapsed: 00:00:00.00
    SQL> Gints Plivna
    http://www.gplivna.eu

  • Optimizing MINUS query

    Hi All,
    Please help me in optimizing my MINUS query, I had created a web portal using pl/sql to view the difference between two data loads into a table each data load has its own version number.
    for example:
    consider table xx
    Ver id opt Wcc code st_dt end_dt rate
    253 2 xx NBK 0 8/1/2002 7/31/2005 0.02
    253 2 xx NBK 0 8/1/2005 3/31/2006 0.01
    258 2 yy BKN 0 4/1/2006 12/31/209 0.01
    258 2 yy BKN 1 8/1/2002 7/31/2005 0.02
    If the table is containing data in thousands my web portal is taking at least 5min to display the difference of the data present for version 253 and 258.
    the MINUS query i have written in my code is
    select
    tab1.id, tab1.opt, tab1.Wcc, tab1.code,tab1.st_dt, tab1.end_dt, tab1.rate
    from xx tab1,
    (SELECT id,opt,Wcc,code,st_dt,rate FROM xx WHERE ver = 253
    minus SELECT id,opt,Wcc,code,st_dt,rate FROM xx WHERE ver = 258 ) tab2
    where tab1.id||tab1.opt||tab1.wcc||tab1.code||tab1.st_dt||tab1.rate=tab2.id||tab2.opt||tab2.Wcc||tab2.code||tab2.st_dt||tab2.rate
    and tab1.ver in (258,253);
    how can i optimize my query so that i can view the difference in min time through the web portal??

    SQL> create table xx
      2  as
      3  select 253 Ver, 2 id, 'xx' opt, 'NBK' Wcc, 0 code, date '2002-08-01' st_dt, date '2005-07-31' end_dt, 0.02 rate from dual union all
      4  select 253, 2, 'xx', 'NBK', 0, date '2005-08-01', date '2006-03-31', 0.01 from dual union all
      5  select 253, 5, 'zz', 'KBN', 1, date '2005-08-01', date '2006-03-31', 0.1 from dual union all
      6  select 258, 2, 'xx', 'NBK', 0, date '2002-08-01', date '2005-07-31', 0.02 from dual union all
      7  select 258, 2, 'xx', 'NBK', 0, date '2005-08-01', date '2006-03-31', 0.5 from dual union all
      8  select 258, 2, 'yy', 'BKN', 1, date '2005-08-01', date '2005-03-31', 0.1 from dual
      9  /
    Tabel is aangemaakt.
    SQL> select ver
      2       , id
      3       , opt
      4       , wcc
      5       , code
      6       , st_dt
      7       , end_dt
      8       , rate
      9       , decode(ver,253,'Deleted',258,'New/Modified') remark
    10    from xx
    11   where ver in (253,258)
    12     and not exists
    13         ( select 'dummy'
    14             from xx xx2
    15            where xx2.id = xx.id
    16              and xx2.opt = xx.opt
    17              and xx2.wcc = xx.wcc
    18              and xx2.code = xx.code
    19              and xx2.st_dt = xx.st_dt
    20              and xx2.end_dt = xx.end_dt
    21              and xx2.rate = xx.rate
    22              and xx2.ver != xx.ver
    23         )
    24  /
      VER    ID OP WCC  CODE ST_DT               END_DT               RATE REMARK
      253     2 xx NBK     0 01-08-2005 00:00:00 31-03-2006 00:00:00   ,01 Deleted
      253     5 zz KBN     1 01-08-2005 00:00:00 31-03-2006 00:00:00    ,1 Deleted
      258     2 xx NBK     0 01-08-2005 00:00:00 31-03-2006 00:00:00    ,5 New/Modified
      258     2 yy BKN     1 01-08-2005 00:00:00 31-03-2005 00:00:00    ,1 New/Modified
    4 rijen zijn geselecteerd.Regards,
    Rob.

  • Minus query in ODI 3.4

    hi everyone ,
    can some please explain me how to do minus query in Odi . i am not allowed to create views so please such suggestion.
    in short some method where i can compare two tables and extract only the data that is present in one table and if both have the same data ignore.
    eg .
    table 1
    id desc flag
    100 sdfsd 3
    101 sdfsd 3
    102 sdfds 3
    table 2
    id desc flag
    100 sdfd 8
    103 sdfd 8
    105 dfsdf 8
    result should be
    id desc flag
    100 sdfsd 3
    101 sdfsd 3
    102 sdfds 3
    103 sdfd 8
    105 dfsdf 8
    i .e 8 should not update 3 flag data . in IKM update its lost and if i put update on both id and flag i have two copies . so i just want to compare and load all the date of table 1 completely and then table 2 which doesnt mached with id .
    Please suggest .

    Hi Dev,
    For the situation as you described do something like:
    1) load the firts table with IKM Control Append
    2) Load the second table with the IKM Incremental Update but change the "UPDATE" option to "NO" and use the ID as KEY.
    That will give you exaclty what you wanted because will only load the new records from second and ignore those that already exists in the target.
    Cezar Santos

  • Sub select query Help

    I have to do a task of finding records which matches the following logic.
    My table has PID varchar(15), Amount varchar (50),Status varchar(20) columns.
    Each PID can go thru changes in a period of time, in my case i dont have a data range I just have a flatfile which consists of three types of PID`s
    123456 = Original_PID, Reversal =123456R1,Adjustment= 123456A1.
    Basically What I am trying to find out if there are any original PID`s which has a Reversal or an Adjustment.
    here`s the code I have started on... Can someone help me get it finished?
    select R1. pid,a1.pid,org.pid from (
    select SUBSTRING(Pid,1,11)as Original_PID, status, paid_amount as Amount from dbo.Q2STATUS)org
    inner join (select SUBSTRING(Pid,1,13)as Original_Icn,status,paid_amount from dbo.Q2STATUS
    where SUBSTRING(Pid,12,2) ='R1')r1 on r1.pid=org.pid
    inner join (select SUBSTRING(claim_id,1,13)as Original_Icn,status,paid_amount from dbo.Q2STATUS
    where SUBSTRING(Pid,12,2) ='A1')A1 on a1.Pid=org.PID
    FM

    Hi,
    Please check following item
    It uses a
    SQL string function, please create it first
    create table Q2STATUS (Pid nvarchar(200), Status varchar(20), paid_amount int)
    insert into Q2STATUS select '123456 = Original_PID, Reversal =123456R1, Adjustment= 123456A1',NULL,250
    with cte2 as (
    select rn = row_number() over (order by pid), * from Q2STATUS
    ), cte as (
    select cte2.*, s.id typeid, v.*
    from cte2
    cross apply dbo.split(cte2.Pid, ',') s
    cross apply dbo.split(s.val, '=') v
    ), cte3 as (
    select
    rn, pid, status, paid_amount, max(pidtype) pidtype, max(pidval) pidval
    from (
    select
    rn, Pid, status, paid_amount, typeid,
    case when (typeid = 1 and id = 2) or (typeid <> 1 and id = 1) then ltrim(rtrim(val)) else null end as pidtype,
    case when (typeid = 1 and id = 1) or (typeid <> 1 and id = 2) then ltrim(rtrim(val)) else null end as pidval
    from cte
    ) g
    group by rn, pid, status, paid_amount, typeid
    select
    cte2.rn, cte2.pid,
    cte3.pidval as 'Original_PID',
    cte4.pidval as 'Reversal',
    cte5.pidval as 'Adjustment'
    from cte2
    left join cte3 on cte3.rn = cte2.rn and pidtype = 'Original_PID'
    left join cte3 as cte4 on cte4.rn = cte2.rn and cte4.pidtype = 'Reversal'
    left join cte3 as cte5 on cte5.rn = cte2.rn and cte5.pidtype = 'Adjustment'
    Here is the result,
    Please note that I have used
    SQL CTE expressions a lot in the SQL query to prevent usage of sub-select and temp tables.
    There is also a
    SQL ROW_NUMBER() function used in the first SELECT statement to distinquish all items from each other instead of using the PID column value. Perhaps you have already an ID key column, you can use it too
    SQL Server, SQL Server 2012 Denali and T-SQL Tutorials

  • Help needed in inserting data using a query

    I need to have some data as a result of the following query:
    select sched_num,load_id,ord_id,split_id from ord_load_seq
    where (ord_id,split_id,sched_num) in (select ord_id,split_id,sched_num from ord_load_seq where seq_num = '2'
    group by ord_id,split_id,sched_num having count(1) >1)
    order by ord_id,split_id,sched_num;
    But currently it retunrns no rows. The problem is in the having count(1)> 1 clause.
    When i make =1, it returns rows. But no rows on > 1. I even tried inserting some rows to get the result >1
    But still the query on a whole returns no rows.Please help.

    ohhh... lets start our lesson children:
    here is code to consider:
    Connected to Oracle Database 10g Enterprise Edition Release 10.2.0.2.0
    SQL>
    SQL> --Q1
    SQL> with tbl as
      2  (select 1 fld1, 1 fld2, 1 fld3 from dual
      3  union all
      4  select 1 fld1, 1 fld2, 2 fld3 from dual
      5  union all
      6  select 1 fld1, 1 fld2, 3 fld3 from dual
      7  union all
      8  select 1 fld1, 2 fld2, 3 fld3 from dual
      9  union all
    10  select 1 fld1, 3 fld2, 3 fld3 from dual)
    11  select  fld1, fld2, fld3 from tbl
    12  order by fld1, fld2, fld3
    13  /
          FLD1       FLD2       FLD3
             1          1          1
             1          1          2
             1          1          3
             1          2          3
             1          3          3
    SQL> --Q2
    SQL> with tbl as
      2  (select 1 fld1, 1 fld2, 1 fld3 from dual
      3  union all
      4  select 1 fld1, 1 fld2, 2 fld3 from dual
      5  union all
      6  select 1 fld1, 1 fld2, 3 fld3 from dual
      7  union all
      8  select 1 fld1, 2 fld2, 3 fld3 from dual
      9  union all
    10  select 1 fld1, 3 fld2, 3 fld3 from dual)
    11  select  fld1, fld2, fld3, count(1) from tbl
    12  group by fld1,fld2,fld3
    13  order by fld1, fld2, fld3
    14  /
          FLD1       FLD2       FLD3   COUNT(1)
             1          1          1          1
             1          1          2          1
             1          1          3          1
             1          2          3          1
             1          3          3          1
    SQL> --Q3
    SQL> with tbl as
      2  (select 1 fld1, 1 fld2, 1 fld3 from dual
      3  union all
      4  select 1 fld1, 1 fld2, 2 fld3 from dual
      5  union all
      6  select 1 fld1, 1 fld2, 3 fld3 from dual
      7  union all
      8  select 1 fld1, 2 fld2, 3 fld3 from dual
      9  union all
    10  select 1 fld1, 3 fld2, 3 fld3 from dual)
    11  select  fld1, fld2, fld3 from tbl
    12  group by fld1,fld2,fld3
    13  having count(1) > 1
    14  order by fld1, fld2, fld3
    15  /
          FLD1       FLD2       FLD3
    SQL> --Q4
    SQL> with tbl as
      2  (select 1 fld1, 1 fld2, 1 fld3 from dual
      3  union all
      4  select 1 fld1, 1 fld2, 2 fld3 from dual
      5  union all
      6  select 1 fld1, 1 fld2, 2 fld3 from dual
      7  union all
      8  select 1 fld1, 1 fld2, 3 fld3 from dual
      9  union all
    10  select 1 fld1, 2 fld2, 3 fld3 from dual
    11  union all
    12  select 1 fld1, 3 fld2, 3 fld3 from dual)
    13  select  fld1, fld2, fld3 from tbl
    14  order by fld1, fld2, fld3
    15  /
          FLD1       FLD2       FLD3
             1          1          1
             1          1          2
             1          1          2
             1          1          3
             1          2          3
             1          3          3
    6 rows selected
    SQL> --Q5
    SQL> with tbl as
      2  (select 1 fld1, 1 fld2, 1 fld3 from dual
      3  union all
      4  select 1 fld1, 1 fld2, 2 fld3 from dual
      5  union all
      6  select 1 fld1, 1 fld2, 2 fld3 from dual -- inserted duplicate row
      7  union all
      8  select 1 fld1, 1 fld2, 3 fld3 from dual
      9  union all
    10  select 1 fld1, 2 fld2, 3 fld3 from dual
    11  union all
    12  select 1 fld1, 3 fld2, 3 fld3 from dual)
    13  select  fld1, fld2, fld3, count(1)   from tbl
    14  group by fld1,fld2,fld3
    15  order by fld1, fld2, fld3
    16  /
          FLD1       FLD2       FLD3   COUNT(1)
             1          1          1          1
             1          1          2          2
             1          1          3          1
             1          2          3          1
             1          3          3          1
    SQL> --Q6
    SQL> with tbl as
      2  (select 1 fld1, 1 fld2, 1 fld3 from dual
      3  union all
      4  select 1 fld1, 1 fld2, 2 fld3 from dual
      5  union all
      6  select 1 fld1, 1 fld2, 2 fld3 from dual -- inserted duplicate row
      7  union all
      8  select 1 fld1, 1 fld2, 3 fld3 from dual
      9  union all
    10  select 1 fld1, 2 fld2, 3 fld3 from dual
    11  union all
    12  select 1 fld1, 3 fld2, 3 fld3 from dual)
    13  select  fld1, fld2, fld3 from tbl
    14  group by fld1,fld2,fld3
    15  having count(1) > 1
    16  order by fld1, fld2, fld3
    17  /
          FLD1       FLD2       FLD3
             1          1          2
    SQL> Q1. As you may see we have an bunch of data where each row is unique combination of the columns value.
    Q2. lets try to group it by fld1 and fld2 and fld3 columns. We don't expect any miracle and got the same data as Q1. Why? Because each row is unique combination(group) in scope of fld1, fld2, fld3 - count(1) exactly shows us that.
    Q3. Q2 is explanation why we got no rows filter (having count(1) > 1)because the result of the clause is always false.
    Q4. Lets put some duplication.
    Q5. Now we got some new result. Count shows us group with more then one rows.
    Q6. Shows us exact group which we've found in Q5.

  • How to insert code in a QUERY

    Hi All,
    I'm creating a Query to extract the data from EKKO, EKPO and EKKN.
    here I have to insert a piece of code as checking below.
    IF EKPO-KNTTP ne '   '.      "not equal to blank
    extract the data from table EKKN.
    ENDIF.
    here I need your help like how to write this code in a Query or Functional Area (Info Set).
    Thanks,
    Sunil Bodda.

    Duplicate POST.....
    select the query and go to QUERY in the menubar then goto more functions where you have an option display report name it will give you the report name.
    Menubar ---> Quer ---> MoreFunctions ----> Display Reportname.
    Goto SE80/SE38-->Report name and add the Codes in the program.
    Regards,
    gurpreet

  • Checkbox in a minus query

    Hello,
    I am trying to use the checkbox function in the following query to produce a report with a checkbox but it is not working correctly -- the query is fine, but does not work when I place the checkbox function within it:
    Select HTMLDB_ITEM.CHECKBOX(1,loginid) Grant,
    lastname || ', ' || firstname fullname
    from arxusers A
    where a.rec_status = 'A'
    minus
    Select a.loginid,
    lastname || ', ' || firstname fullname
    from arxusers a , arxaccess b
    where a.loginid = b.loginid
    and b.rpt_id = :id
    and a.rec_status = 'A'
    Says from keyword not found where expected -- Can you not use the checkbox with a 'minus' SQL query

    Can anyone please help me with this -- I even changed my query to a 'not exists' and I still get the same, 'From keyword not found where expected' error. Is the checkbox function in a report limited to just basic SQL report queries? That does not make sense. Here is my new query getting the same error:
    SELECT HTMLDB_ITEM.CHECKBOX(1,a.loginid) Grant,
    a.lastname || ', ' || a.firstname
    from arxusers A
    where a.rec_status = 'A'
    and not exists (
    select 'Y'
    from arxaccess b
    where a.loginid = b.loginid
    and b.rpt_id = :id)
    Any help would be great.
    Thanks,
    Jeff

  • How to insert code conditions ina QUERY

    Hi All,
    I'm creating a Query to extract the data from EKKO, EKPO and EKKN.
    here I have to insert a piece of code as checking below.
    IF EKPO-KNTTP ne '   '.      "not equal to blank
    extract the data from table EKKN.
    ENDIF.
    here I need your help like how to write this code in a Query.
    Thanks,
    Sunil Bodda.
    Edited by: sunil bodda on Apr 15, 2009 12:05 PM

    Hi Sunil,
    You need to code it in infoset. follow the steps below.
    1. Goto SQ02, enter your infoset.
    2. Click on "Extras" button(above find button). On the next page you will find a "Code" tab. 
    3. Declare a constant as space. choose DATA in the drop down for coding section.
    4. Choose "Record processing" or if any other appropriate choice from the drop down in the coding section.
    5. CHECK EKPO-KNTTP EQ c_space. and write your code here.
    Hope this helps.

Maybe you are looking for

  • Not able to create service requests in E-Service

    HI all, I am unable to create service requests in the e-service scenario, after i enter all the data and press save button, it says that number is null. There is no dump in the crm system. I am able to create the same service request in CRM system an

  • Filter the data loads by material type = FERT or UNBW

    Hi All, I have to load the data from DSO to Cube in which I have to filter by material type = FERT or UNBW, actually this material type is the nav attribute of 0material. But I dont have this 0material or 0matl_type in the source i.e. DSO. How can I

  • Bizarre bug in Pages?

    I have just finished the first draft of my new novel, but have discovered what at first appears to be an odd bug in Pages. Words that have a 'k' in the middle of them, such as 'making', now appear with that letter capitalised, as in 'maKing'. I am ce

  • Question - Aperture Preview Settings

    I import RAW photo files from my Canon S95 camera into Aperture 3.1.2, then touch them up a little (sharpen, straighten, correct lens distortion).  I have read that the Aperture screen display of the newly-created Versions is influenced by the settin

  • How to use a script to kill only forms sessions idle for over 30 minutes?

    We want to use a script to kill forms users idle for over 30 minutes, but we don't want to kill background concurrent processes waiting for resources. even though we set up the timeout but it won't work for users who exit forms ungracefully. thanks!