Delete Query Help

I need to find the best way to find the most current record based on the cust_no, cust_prompt, class_code and delete the older lines from my table but keeping the most current line. What would be the best way to do such?
Table1
cust_no cust_prompt class_code start_date
1234     1     B     1-jan-11
1234     1     B      2-jan-11
1234     1     B      3-jan-11
7890     2     C     4-oct-10
7890     2     C     7-jul-10
7890     2     C     1-dec-10
I have used the RANK function to identify the the lines that need to be deleted but I am struggling on writing the query that deletes the older lines. Below is the query that I am using to find the older lines.
select * from (
select cust_no, cust_prompt, class_code, start_date
rank() Over (Partition by cust_no, cust_prompt, class_code ORDER BY start_date desc) rank
FROM Table1)
where rank>1

user9339442 wrote:
I need to find the best way to find the most current record based on the cust_no, cust_prompt, class_code and delete the older lines from my table but keeping the most current line. What would be the best way to do such?
Table1
cust_no cust_prompt class_code start_date
1234     1     B     1-jan-11
1234     1     B      2-jan-11
1234     1     B      3-jan-11
7890     2     C     4-oct-10
7890     2     C     7-jul-10
7890     2     C     1-dec-10
I have used the RANK function to identify the the lines that need to be deleted but I am struggling on writing the query that deletes the older lines. Below is the query that I am using to find the older lines.
select * from (
select cust_no, cust_prompt, class_code, start_date
rank() Over (Partition by cust_no, cust_prompt, class_code ORDER BY start_date desc) rank
FROM Table1)
where rank>1
delete table1 where rowid in
select the_row_id
from
  select
   rowid as the_row_id,
   rank() Over (Partition by cust_no, cust_prompt, class_code ORDER BY start_date desc) rank
  FROM Table1
where rank>1
);Should do it.

Similar Messages

  • Plsql/sql iterative delete query help

    I need some help.....I have 4 tables joined by TRANSACTION_ID
    TRANSACTIONS Table
    TRANSACTION_ID NUMBER(20)
    USER_ID NUMBER(20)
    EXPIRY TIMESTAMP
    TX_ATTEMPTS Table
    TX_ATTEMPT_ID NUMBER(20)
    TRANSACTION_ID NUMBER(20)
    TX_ELEMENTS
    TX_ELEMENT_ID NUMBER(20)
    TRANSACTION_ID NUMBER(20)
    CIDENT
    CIDENT_ID NUMBER(20)
    Each TRANSACTION has an associated
    USER_ID - ID identitying a unique person
    EXPIRY - Timestamp to indicate when the TRANSACTION expires in the system.
    A USER_ID can have many TRANSACTIONS associated with it.
    I'm looking for some PL/SQL that will accept a variable (RETAIN_NUM) indicating the number of most recent transactions that need to be retained for all users in the database.
    For example if the RETAIN_NUM is 5, the sql should do the following:
    1) Retain the 5 most recent transactions in the TRANSACTIONS table for each USER_ID (including associated entries in the other 3 tables also). All older entries for each USER_ID should be deleted from the TRANSACTIONS table (including any associated entries in the other 3 tables also).
    2) Before deleting the data in all the tables I want to export it, ideally using expdp in a single execution.
    Is there anyone that could please help me with either part of this??
    Edited by: user12213281 on Jun 4, 2013 3:47 PM

    Thanks for your comments. The way the system works is complicated and I'm not sure how to tackle the overall delete...that is why I have asked for some help.
    I have examined the schema structure again and have identified some useful points to make it easier.
    Each of the tables have several other columns but I had stripped them down for the purpose of making this query easier to understand. Luckily each of the tables in the schema do have a CIDENT_ID column with a cascade delete constraint from the CIDENT table. This works most simply for the TX_ELEMENTS table so I don't think I will need to include that table specifically in any delete. Unfortunately at this time I am not able to create any other new relationships between the tables.
    The tables involved now are:
    TRANSACTIONS Table
    CIDENT_ID NUMBER(20)
    TRANSACTION_ID NUMBER(20)
    USER_ID NUMBER(20)
    EXPIRY TIMESTAMP
    TX_ATTEMPTS Table
    CIDENT_ID NUMBER(20)
    TX_ATTEMPT_ID NUMBER(20)
    TRANSACTION_ID NUMBER(20)
    CIDENT Table
    CIDENT_ID NUMBER(20)
    The difficulty comes with the TRANSACTIONS and TX_ATTEMPTS tables.
    Each TRANSACTIONS and TX_ATTEMPTS entry has a completely separate CIDENT entry. What I was thinking I need to do is:
    1) Generate a list of TRANSACTION_IDs and corresponding CIDENT_IDs from the TRANSACTIONS table that are the most recent "retain_num" entries for each USER_ID (using EXPIRY_DTM).
    2) Then generate a list of CIDENT_IDs from the TX_ATTEMPTS table based on the TRANSACTION_IDs from 1) above
    3) Delete the CIDENT entries using the CIDENT_IDs obtained from 1) and 2) above.
    These individually may not be so bad but I don't know how to combine them....
    Any pointers would really be greatly appreciated...

  • Help!! -- DELETE query

    Hi There
    I need your help in creating a SQL query. The situation is as follows:
    I have three tables in a database (Team, Entry, Athlete). They are linked as follows:
    TEAM          ATHLETE          ENTRY
    TeamID ...     AthleteID ...     EntryID
    Name     .     LastName    .     EventID
    Sname      .     FirstName   ....AthleteID
    Tel      .......TeamID          LaneI need to do a DELETE query where I delete all records where the TeamID field equals a variable named A.
    Both Team and Athlete includes a field named TeamID so that part is easy.
    The trick is where I need to delete the records in the table named Entry. This table does not include a field named TeamID. It does include a field named AthleteID though. So, what needs to happen is I have to first do a query to find a list of records in Athlete whose TeamID is equal to A. From that list it needs to return all the AthleteID values. Then I need a query that will delete all the records in Event that contain those AthleteID's.
    I hope this makes sense. Please tell me if I need to explain something better!
    Hope to hear from you soon.
    Kind regards,
    Comlink

    Probably depends on the actual database....
    delete from entry
    where athleteID in (select AtheletID from athelete where TeamId=A)

  • SAP BW query view deletion in Web/ "Delete Query view" in web

    Dear All,
    We are using the standard template: BW web analyzer (0ANALYZER). In this standard template, SAP provided two links "Save View" and "Open View" for creating new query views and opening existing query views respectively. However, no oppurtunity was provided to "delete query views".
    We would like to have an oppurtunity to delete the query views as well from Web. (currently we are deleting the unwanted query views from Bex analyzer, as per the request from business users - who have access only to the web reports).
    Would be great if you can suggest some solution to this problem.
    By the way, We would not like to use the standard "Query view selection" web item. (as it creates user specic local views only).
    best regards.

    Hi atlaj
    There is a Function Module called
    CALL FUNCTION 'RZX2_OBJECT_DELETE'
    you can make yourselves a little ABAP with.
    Hope this Helps.
    Best Regards
    Armin Baggenstos

  • Delete query is taking too much time...

    Hi All,
    Below delete query is taking at least 1hrs. !!!!
    DELETE aux_current_link aux
    WHERE EXISTS (
    SELECT *
    FROM link_trans_cons link2
    WHERE aux.tr_leu_id = link2.tr_leu_id
    AND aux.kind_of_link = link2.kind_of_link
    AND link2.TYPE = 'H');
    table aux_current_link has record - 284279 and has 6 normal index.
    pls help me.
    Subir

    Not even close to enough information.
    Look here to see if you can tune the operation.
    When your query takes too long ...
    But for a delete you need to understand that the indexes need to be maintained, you have 6 of them, that requires effort. ALSO, foreign keys need to be checked to make sure you don't violate any enabled foreign keys (so maybe you need an index on a table where a column from this table you deleting from is being referenced).
    If you are deleting a HIGH percentage of the table you may be better off doing a create table as select ....query to keep all rows from your table....then drop your current table, rename the new one you made, and add all the indexes to it.
    Otherwise, once you've tuned the operation (query), assuming it can be tuned, it's going to take as long as it needs to take.....
    Message was edited by:
    Tubby

  • Delete query not working ?

    hi all,
    this delete query is not working for me. Could you please help me and tell me ho to resolve this ? The error i get when executing this query is "ORA-00903: invalid table name". The table name is correct I fail to understand why does it show invalid table name.
    Thanking you all.
    Regards

    Obviously the table name isn't correct. Either that, or the user that the query is running under doesn't have permissions to view it, so it's getting the response that the table does not exist.
    Look at the user you are connecting as. Log in to sqlplus and make sure that user has select perms on the table.
    Check your spelling of the table name. Typos happen.

  • Deletion Query takes too long

    I have two tables with exactly the same structure. The table 1 gets data and one procedure reads that data and inserts them into another table (table2) for processing them. I have a delete query which is taking too long to execute.
    The query is as follows
    delete
    from events.temp_act a
    where a.chess_ts < (select max(chess_ts) from events.temp_act b
    where a.db_type = b.db_type
    and a.order_no = b.order_no
    and a.acv_no = b.acv_no
    There is a composite index in this table which is (db_type,order_no,acv_no)
    In my procedure, I drop and create the index for faster processing and also analyze the index.
    The above deletion query approximately deletes half the number of total records.
    There is no primary key in the table for the reason that there can be no unique record identifier.
    The query takes nearly 2 hours for deleting about 1100000 records.
    Is there a way to make this query run faster?

    What is the explain plan for this statement? Is the index even being used?
    Is the table analyzed as well as the index?
    Dropping/re-creating the index - not likely to help. I would leave this out.
    Have you tried other variations, like:
    delete
      from events.temp_act
    where (db_type, order_no, acv_vo, chess_ts)
           not in (select db_type, order_no, acv_vo, max(chess_ts)
                     from events.temp_act b
                    group by db_type, order_no, acv_vo);

  • Delete Query takes more time

    Hi,
    My database in 10g(10.2.0.4), I fire delete query which deletes 5 Lacs records from the table but it is taking more time to delete.
    My table and indexes on that table in Nologging mode, Database in Archive Log Mode.
    Can you please help to minize the time?
    Execution Plan
    0 DELETE STATEMENT Optimizer=ALL_ROWS (Cost=2 Card=1 Bytes=62)
    1 0 DELETE OF 'CORP_MESSAGEQUEUE'
    2 1 INDEX (RANGE SCAN) OF 'INDEX_CORP_MESSAGEQUEUE_PROC' (IN
    DEX) (Cost=2 Card=1 Bytes=62)
    Statistics
    754 recursive calls
    635137 db block gets
    4773 consistent gets
    181579 physical reads
    268073944 redo size
    630 bytes sent via SQL*Net to client
    608 bytes received via SQL*Net from client
    3 SQL*Net roundtrips to/from client
    1 sorts (memory)
    4 sorts (disk)
    483328 rows processed
    Anand

    Even if the table is in nologing mode there will be redo generated for the DML. It is clear from your statistics that redo is being generated for the delete. Loging is only effective for few of the operations as given bellow. I think there is no issue with the query the redo and undo generation is taking time. Just tune your configuration like.
    No redo log files.
    size of redo log.
    Undo tablespace size.
    undo retentation.
    Pga_aggrigate_target.
    temporary tablespace sizing.
    754 recursive calls
    635137 db block gets
    4773 consistent gets
    181579 physical reads
    **268073944 redo size**
    630 bytes sent via SQL*Net to client
    608 bytes received via SQL*Net from client
    3 SQL*Net roundtrips to/from client
    1 sorts (memory)
    4 sorts (disk)
    483328 rows processed
    NOLOGGING: Oracle will generate a minimal number of redo log entries in order to protect the data dictionary, and the operation will probably run faster. Logging can be disabled at the table level or the tablespace level.
    If it is done at the tablespace level then we create indexes or tables in this tablespace; they will be in NOLOGGING mode.
    A table or an index can be created with NOLOGGING mode or it can be altered using ALTER TABLE/INDEX NOLOGGING.
    NOLOGGING is active in the following situations and while running one of the following commands but not after that.
    - DIRECT LOAD (SQL*Loader)
    - DIRECT LOAD INSERT (using APPEND hint)
    - CREATE TABLE ... AS SELECT
    - CREATE INDEX
    - ALTER TABLE MOVE
    - ALTER TABLE ... MOVE PARTITION
    - ALTER TABLE ... SPLIT PARTITION
    - ALTER TABLE ... ADD PARTITION (if HASH partition)
    - ALTER TABLE ... MERGE PARTITION
    - ALTER TABLE ... MODIFY PARTITION, ADD SUBPARTITON, COALESCE SUBPARTITON, REBUILD UNUSABLE INDEXES
    - ALTER INDEX ... SPLIT PARTITION
    - ALTER INDEX ... REBUILD
    - ALTER INDEX ... REBUILD PARTITION
    Logging is stopped only while one of the commands above is running.
    So if a user runs this:
    ALTER INDEX new_index NOLOGGING.
    The actual rebuild of the index does not generate redo (all data dictionary changes associated with the rebuild will do) but after that any DML on the index will generate redo this includes direct load insert on the table which the index belongs to.
    All the following statements will generate redo despite the fact the table is in NOLOGGING mode:
    - INSERT INTO new_table_nolog_test ...,
    - UPDATE new_table_nolog_test SET ...,
    - DELETE FROM new_table_nolog_test ..
    The following will not generate redo (except from dictionary changes and indexes):
    - INSERT /*APPEND/ ...
    - ALTER TABLE new_table_nolog_test MOVE ...
    - ALTER TABLE new_table_nolog_test MOVE PARTITION ...
    practicle example:
    SQL> select value OLD_VALUE
    from v$mystat, v$statname
    where v$mystat.statistic# = v$statname.statistic#
    and v$statname.name = 'redo size'; 2 3 4
    OLD_VALUE
    0
    SQL> /
    OLD_VALUE
    0
    SQL>
    SQL> create table T_NOLOG nologging as select * from all_objects;
    Table created.
    SQL> select (value - &OLD_VALUE) OLD_VALUE
    from v$mystat, v$statname
    where v$mystat.statistic# = v$statname.statistic#
    and v$statname.name = 'redo size'; 2 3 4
    Enter value for old_value: 0
    old 1: select (value - &OLD_VALUE) OLD_VALUE
    new 1: select (value - 0) OLD_VALUE
    OLD_VALUE
    91848
    SQL> delete from T_NOLOG ;
    106229 rows deleted.
    SQL> select (value - &OLD_VALUE) OLD_VALUE
    from v$mystat, v$statname
    where v$mystat.statistic# = v$statname.statistic#
    and v$statname.name = 'redo size'; 2 3 4
    Enter value for old_value: 91848
    old 1: select (value - &OLD_VALUE) OLD_VALUE
    new 1: select (value - 91848) OLD_VALUE
    OLD_VALUE
    39389988
    SQL>

  • Delete query is slow in one schema.

    Hi All,
    I have two schemas in a database PRDPUB and TOOLSERVER . In both the schemas i have a table BP_USER_PROFILE containg same amount of data , indexes and constrains. I am using one delete query to delete 26000 records from both the table , but in PRDPUB schema it is hanging but in TOOLSERVER schema it is running fine.When i tried to delete 100 records using the same query in PRDPUB schema it is taking 44 second nad 13 milisecond in TOOLSERVER.
    when i generated the exution plan it is very much same .But when i see the trace file i see in PRDPUB schema it is accessing the disk and doing parsing and execution 2 times , while in TOOLSERVER schema it is deleting in memory and parsing and executing once.
    For your reference i am attching the expalin plan and trace file output. Please help me out to resolve the issue.
    explain plan for delete from bp_user_profile where id_user in (select id_user from (SELECT * FROM bp_user_profile WHERE
    id_home_category=5005 AND DT_USER_LAST_UPDATED <'01-DEC-09' AND ID_USER_STATUS_ACTIVE ='DELETED_BY_ADMIN'
    OR ID_USER_STATUS_ACTIVE ='DELETED_BY_USER') where rownum<=100);
    PLAN_TABLE_OUTPUT in PRDPUB schema
    Plan hash value: 288284804
    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
    | 0 | DELETE STATEMENT | | 100 | 7600 | 1906 (1)| 00:00:23 |
    | 1 | DELETE | BP_USER_PROFILE | | | | |
    | 2 | NESTED LOOPS | | 100 | 7600 | 1906 (1)| 00:00:23 |
    | 3 | VIEW | VW_NSO_1 | 100 | 1300 | 1885 (1)| 00:00:23 |
    | 4 | SORT UNIQUE | | 100 | 2100 | | |
    |* 5 | COUNT STOPKEY | | | | | |
    |* 6 | TABLE ACCESS BY INDEX ROWID | BP_USER_PROFILE | 86428 | 1772K| 1885 (1)| 00:00:23 |
    | 7 | BITMAP CONVERSION TO ROWIDS | | | | | |
    | 8 | BITMAP OR | | | | | |
    | 9 | BITMAP CONVERSION FROM ROWIDS | | | | | |
    |* 10 | INDEX RANGE SCAN | BP_USER_PROFILE_ID_USER_STATUS | | | 12 (0)| 00:00:01 |
    | 11 | BITMAP AND | | | | | |
    | 12 | BITMAP CONVERSION FROM ROWIDS| | | | | |
    |* 13 | INDEX RANGE SCAN | BP_USER_PROFILE_ID_USER_STATUS | | | 2 (0)| 00:00:01 |
    | 14 | BITMAP CONVERSION FROM ROWIDS| | | | | |
    |* 15 | INDEX RANGE SCAN | BP_USR_PROF_IDCATG | | | 79 (2)| 00:00:01 |
    |* 16 | INDEX UNIQUE SCAN | BP_USR_PROF_PK_ID_USER | 1 | 63 | 1 (0)| 00:00:01 |
    PLAN_TABLE_OUTPUT
    Predicate Information (identified by operation id):
    5 - filter(ROWNUM<=100)
    6 - filter("ID_USER_STATUS_ACTIVE"='DELETED_BY_USER' OR "ID_USER_STATUS_ACTIVE"='DELETED_BY_ADMIN' AND
    "ID_HOME_CATEGORY"=5005 AND "DT_USER_LAST_UPDATED"<'01-DEC-09')
    10 - access("ID_USER_STATUS_ACTIVE"='DELETED_BY_USER')
    13 - access("ID_USER_STATUS_ACTIVE"='DELETED_BY_ADMIN')
    15 - access("ID_HOME_CATEGORY"=5005)
    PLAN_TABLE_OUTPUT
    16 - access("ID_USER"="$nso_col_1")
    PLAN_TABLE_OUTPUT
    Plan hash value: 288284804
    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
    | 0 | DELETE STATEMENT | | 102 | 7752 | 2892 (2)| 00:00:35 |
    | 1 | DELETE | BP_USER_PROFILE | | | | |
    | 2 | NESTED LOOPS | | 102 | 7752 | 2892 (2)| 00:00:35 |
    | 3 | VIEW | VW_NSO_1 | 100 | 1300 | 2871 (1)| 00:00:35 |
    | 4 | SORT UNIQUE | | 100 | 2100 | | |
    |* 5 | COUNT STOPKEY | | | | | |
    |* 6 | TABLE ACCESS BY INDEX ROWID | BP_USER_PROFILE | 170K| 3500K| 2871 (1)| 00:00:35 |
    | 7 | BITMAP CONVERSION TO ROWIDS | | | | | |
    | 8 | BITMAP OR | | | | | |
    | 9 | BITMAP CONVERSION FROM ROWIDS | | | | | |
    |* 10 | INDEX RANGE SCAN | BP_USER_PROFILE_ID_USER_STATUS | | | 22 (0)| 00:00:01 |
    | 11 | BITMAP AND | | | | | |
    | 12 | BITMAP CONVERSION FROM ROWIDS| | | | | |
    |* 13 | INDEX RANGE SCAN | BP_USER_PROFILE_ID_USER_STATUS | | | 22 (0)| 00:00:01 |
    | 14 | BITMAP CONVERSION FROM ROWIDS| | | | | |
    |* 15 | INDEX RANGE SCAN | BP_USR_PROF_IDCATG | | | 78 (2)| 00:00:01 |
    |* 16 | INDEX UNIQUE SCAN | BP_USR_PROF_PK_ID_USER | 1 | 63 | 1 (0)| 00:00:01 |
    PLAN_TABLE_OUTPUT
    Predicate Information (identified by operation id):
    5 - filter(ROWNUM<=100)
    6 - filter("ID_USER_STATUS_ACTIVE"='DELETED_BY_USER' OR "ID_USER_STATUS_ACTIVE"='DELETED_BY_ADMIN' AND
    "ID_HOME_CATEGORY"=5005 AND "DT_USER_LAST_UPDATED"<'01-DEC-09')
    10 - access("ID_USER_STATUS_ACTIVE"='DELETED_BY_USER')
    13 - access("ID_USER_STATUS_ACTIVE"='DELETED_BY_ADMIN')
    15 - access("ID_HOME_CATEGORY"=5005)
    PLAN_TABLE_OUTPUT
    16 - access("ID_USER"="$nso_col_1")
    34 rows selected.
    =====================================
    trace file out put:
    delete from prdpub.bp_user_profile where id_user in (select id_user from (SELECT * FROM prdpub.bp_user_profile WHERE
    id_home_category=:"SYS_B_0" AND DT_USER_LAST_UPDATED <:"SYS_B_1" AND ID_USER_STATUS_ACTIVE =:"SYS_B_2"
    OR ID_USER_STATUS_ACTIVE =:"SYS_B_3") where rownum<=:"SYS_B_4")
    call count cpu elapsed disk query current rows
    Parse 2 0.00 0.00 0 0 0 0
    Execute 2 0.61 0.61 1027 1574 8292 200
    Fetch 0 0.00 0.00 0 0 0 0
    total 4 0.61 0.61 1027 1574 8292 200
    Misses in library cache during parse: 1
    Misses in library cache during execute: 1
    Optimizer mode: ALL_ROWS
    Parsing user id: SYS
    Rows Row Source Operation
    0 DELETE BP_USER_PROFILE (cr=1542994 pr=527 pw=0 time=43954914 us)
    100 NESTED LOOPS (cr=794 pr=13 pw=0 time=125348 us)
    100 VIEW VW_NSO_1 (cr=558 pr=0 pw=0 time=95818 us)
    100 SORT UNIQUE (cr=558 pr=0 pw=0 time=95618 us)
    100 COUNT STOPKEY (cr=558 pr=0 pw=0 time=94328 us)
    100 TABLE ACCESS BY INDEX ROWID BP_USER_PROFILE (cr=558 pr=0 pw=0 time=94325 us)
    103 BITMAP CONVERSION TO ROWIDS (cr=481 pr=0 pw=0 time=93891 us)
    1 BITMAP OR (cr=481 pr=0 pw=0 time=93879 us)
    1 BITMAP CONVERSION FROM ROWIDS (cr=88 pr=0 pw=0 time=11643 us)
    22224 INDEX RANGE SCAN BP_USER_PROFILE_ID_USER_STATUS (cr=88 pr=0 pw=0 time=77 us)(object id 89712)
    1 BITMAP AND (cr=393 pr=0 pw=0 time=80750 us)
    1 BITMAP CONVERSION FROM ROWIDS (cr=10 pr=0 pw=0 time=1150 us)
    1911 INDEX RANGE SCAN BP_USER_PROFILE_ID_USER_STATUS (cr=10 pr=0 pw=0 time=21 us)(object id 89712)
    3 BITMAP CONVERSION FROM ROWIDS (cr=383 pr=0 pw=0 time=105831 us)
    181506 INDEX RANGE SCAN BP_USR_PROF_IDCATG (cr=383 pr=0 pw=0 time=26 us)(object id 88278)
    100 INDEX UNIQUE SCAN BP_USR_PROF_PK_ID_USER (cr=236 pr=13 pw=0 time=8945 us)(object id 88279)
    delete from toolserver.bp_user_profile where id_user in (select id_user from (SELECT * FROM toolserver.bp_user_profile WHERE
    id_home_category=:"SYS_B_0" AND DT_USER_LAST_UPDATED <:"SYS_B_1" AND ID_USER_STATUS_ACTIVE =:"SYS_B_2"
    OR ID_USER_STATUS_ACTIVE =:"SYS_B_3") where rownum<=:"SYS_B_4")
    call count cpu elapsed disk query current rows
    Parse 1 0.00 0.00 0 0 0 0
    Execute 1 0.13 0.12 0 741 3144 100
    Fetch 0 0.00 0.00 0 0 0 0
    total 2 0.13 0.12 0 741 3144 100
    Misses in library cache during parse: 1
    Misses in library cache during execute: 1
    Optimizer mode: ALL_ROWS
    Parsing user id: SYS
    Rows Row Source Operation
    0 DELETE BP_USER_PROFILE (cr=741 pr=0 pw=0 time=123855 us)
    100 NESTED LOOPS (cr=741 pr=0 pw=0 time=95704 us)
    100 VIEW VW_NSO_1 (cr=528 pr=0 pw=0 time=94093 us)
    100 SORT UNIQUE (cr=528 pr=0 pw=0 time=94091 us)
    100 COUNT STOPKEY (cr=528 pr=0 pw=0 time=93729 us)
    100 TABLE ACCESS BY INDEX ROWID BP_USER_PROFILE (cr=528 pr=0 pw=0 time=93724 us)
    102 BITMAP CONVERSION TO ROWIDS (cr=490 pr=0 pw=0 time=93380 us)
    1 BITMAP OR (cr=490 pr=0 pw=0 time=93369 us)
    1 BITMAP CONVERSION FROM ROWIDS (cr=93 pr=0 pw=0 time=11663 us)
    22722 INDEX RANGE SCAN BP_USER_PROFILE_ID_USER_STATUS (cr=93 pr=0 pw=0 time=78 us)(object id 87755)
    1 BITMAP AND (cr=397 pr=0 pw=0 time=80340 us)
    1 BITMAP CONVERSION FROM ROWIDS (cr=11 pr=0 pw=0 time=1118 us)
    1911 INDEX RANGE SCAN BP_USER_PROFILE_ID_USER_STATUS (cr=11 pr=0 pw=0 time=15 us)(object id 87755)
    3 BITMAP CONVERSION FROM ROWIDS (cr=386 pr=0 pw=0 time=104382 us)
    181849 INDEX RANGE SCAN BP_USR_PROF_IDCATG (cr=386 pr=0 pw=0 time=24 us)(object id 87758)
    100 INDEX UNIQUE SCAN BP_USR_PROF_PK_ID_USER (cr=213 pr=0 pw=0 time=1194 us)(object id 87754)
    Edited by: user12956550 on Apr 8, 2010 11:03 AM

    Hi,
    is your delete correct?
    delete from toolserver.bp_user_profile where id_user in (select id_user from (SELECT * FROM toolserver.bp_user_profile WHERE
    id_home_category=:"SYS_B_0" AND DT_USER_LAST_UPDATED <:"SYS_B_1" AND ID_USER_STATUS_ACTIVE =:"SYS_B_2"
    OR ID_USER_STATUS_ACTIVE =:"SYS_B_3") where rownum<=:"SYS_B_4")There is a suspected OR in the where clause, I expect you have to check both statusses with the date and home category, so I think your query should be (add parenthesisses around the two statusses):
    delete from toolserver.bp_user_profile where id_user in (select id_user from (SELECT * FROM toolserver.bp_user_profile WHERE
    id_home_category=:"SYS_B_0" AND DT_USER_LAST_UPDATED <:"SYS_B_1"
    AND
    ( -- added
    ID_USER_STATUS_ACTIVE =:"SYS_B_2"
    OR ID_USER_STATUS_ACTIVE =:"SYS_B_3"
    ) -- added
    ) where rownum<=:"SYS_B_4")Further is the content the same, if these are different, you could also have differences in execution time.
    Herald ten Dam
    Superconsult.nl

  • Findout a deleted query

    Hi,
    Is there any table or anyother way in BW to findout the deleted query details. I want to check who has deleted a particular query and which date ....etc....
    Appreaciate for your help in this regard.
      - BK

    Query Deletion can be found only in the Application Log. I think you need to contact the System Admistration.
    Again, if the query is already transported, then the best way to find would be to find out the request number in which this query has been deleted.

  • Retrieve deleted query

    Hi Experts,
    Is there any way to retrieve a deleted query in BID?
    Any help will be appreciated.
    Rgrds,
    Vaishnavi.........

    Hello Vaishnavi,  
    Once the query is deleted it will be permenantly deleted.
    Any way just let me know how you deleted?, because when you delete a query assigned to a role or user then it will ask you whether to delete it from Role or permenantly. If you have choosen the 2nd option, the chances are remote.
    Check thes table for your query RSRREPDIR, RSZCOMPDIR.
    Otherwise if you have created a new one. Also check if there is any copy of the same query.
    Thanks
    [Chandran|http://chandranonline.blogspot.com/]

  • How to delete Query views

    Hi,
    I have created 2 query views on a particular query in BI 7.
    Now we don't need those query views , so we need to delete them. How can we delete them ?
    1. I tried openeing Bex analyzer and opening query, query view, right click and delete. but the 'Delete' option is disabled.
    2. I tried using 'RSZDELETE' but there is no chance to delete query view.
    plz help me as soon as posiible.
    Thank u.

    Hi
    1. Enter into SAP Easy Access or use tcode (SESSION_MANAGER)
    2. go into SAP MENU -> INFORMATION SYSTEMS ->BUSSINESS INFORMATION WAREHOUSE -> BUSINESS EXPLORER -> QUERY -> DELETE OBJECTS
    3. u will enter into "Deletion of Query objects"
       enter      TYPE -: QUERY
                     INFOCUBE -> name of infocube
                     TECHNICAL NAME -> name of the query
    and EXECUTE it.
    ur query view will be deleted.
    assign points if helpfull
    From
    ManesH

  • How Can I Restore Deleted Query?

    Hi, gurus.
    Can anybody tell me How Can I Restore Deleted Query?
    Help me plz.

    If it has only been deleted from the role and not the object completely then it could still be found within infoareas in Bex, if the object has been deleted completely you could re-transport the query from the development system assuming it was created her in the first instance.
    I'm not sure if you can retrieve the query any other way, i do know there are procedures for workbook retrieval but for querys im not certain.

  • Delete query using inner join

    I need to delete records from a table using inner join from other tables. See below for the table structure and records.
    CREATE TABLE STUDENT (ROLL_NO NUMBER(10),NAME VARCHAR2(100),DEPT_NO NUMBER(10),JOIN_DATE DATE);
    CREATE TABLE DEPART (DEPT_NO NUMBER(10), DEPT_NAME VARCHAR2(100));
    CREATE TABLE ACTIVE_DEPT (DEPT_NO NUMBER(10), IS_ACTIVE VARCHAR2(1));
    INSERT INTO STUDENT (ROLL_NO,NAME,DEPT_NO,JOIN_DATE) VALUES(1,'SAM',10,SYSDATE-10);
    INSERT INTO STUDENT (ROLL_NO,NAME,DEPT_NO,JOIN_DATE) VALUES(2,'ALEX',10,SYSDATE -10);
    INSERT INTO STUDENT (ROLL_NO,NAME,DEPT_NO,JOIN_DATE) VALUES(3,'FRANK',20,SYSDATE -10);
    INSERT INTO STUDENT (ROLL_NO,NAME,DEPT_NO,JOIN_DATE) VALUES(4,'WAYNE',20,SYSDATE+1);
    INSERT INTO STUDENT (ROLL_NO,NAME,DEPT_NO,JOIN_DATE) VALUES(5,'KRUL',30,SYSDATE -10);
    INSERT INTO STUDENT (ROLL_NO,NAME,DEPT_NO,JOIN_DATE) VALUES(6,'ALICE',40,SYSDATE -10);
    INSERT INTO DEPART (DEPT_NO,DEPT_NAME) VALUES (10,'DEPT1');
    INSERT INTO DEPART (DEPT_NO,DEPT_NAME) VALUES (20,'DEPT2');
    INSERT INTO DEPART (DEPT_NO,DEPT_NAME) VALUES (30,'DEPT3');
    INSERT INTO ACTIVE_DEPT (DEPT_NO,IS_ACTIVE) VALUES (10,'Y');
    INSERT INTO ACTIVE_DEPT (DEPT_NO,IS_ACTIVE) VALUES (20,'N');
    INSERT INTO ACTIVE_DEPT (DEPT_NO,IS_ACTIVE) VALUES (30,'Y');
    DELETE FROM STUDENT WHERE (STUDENT.DEPT_NO) IN (SELECT D.dept_no FROM DEPART D,ACTIVE_DEPT AD WHERE D.DEPT_NO = AD.DEPT_NO AND AD.IS_ACTIVE = 'N');The above delete query will delete two records from the STUDENT table. Now i want to include another condition say, join_date should be a past date (join_date < trunc(sysdate)).
    How to include this condition in the above delete statement. I know i can do this using a subquery but i wont prefer that option. Basically i don't have much idea about join in delete statements.
    Please help.

    Is this you need ?
    DELETE FROM student WHERE join_date < TRUNC(SYSDATE)
                                            AND student.dept_no IN (SELECT D.dept_no
                                                                      FROM depart d,active_dept ad
                                                                     WHERE d.dept_no = ad.dept_no AND ad.is_active = 'N');Only one record is deleted. -> 3,'FRANK',20,SYSDATE -10
    >
    Balaji      wrote:
    Yes. But here we are getting the dept_no from the sub query, is there a better way to achieve this without sub query?
    >
    As far I know you need to have sub query in this case.
    You can close this thread if answered. If you have any further queries please post it so that someone can help you.
    Edited by: Lokanath Giri on २० मार्च, २०१२ ५:०५ अपराह्न

  • Query Help-2

    Query Help:
    http://forum.java.sun.com/thread.jsp?forum=45&thread=471180&tstart=15&trange=15
    It seems I have confused enough people with my improper presentation of query. Sorry guys. I will restate my question with different table names.
    The above was my previous posting, which was not clear..so Iam restating my problem as follows....
    I have the following tables
    Customer(custID, Name, Address)
    Order(custID, OrderID, orderDate)
    CreditCard(custID, creditCard#, creditCardType)
    Now if I have 3 records in Order with custID 100 and 2 records in CreditCard as
    Order:
    100,A001,11/22/03
    100,A002,11/24/03
    100,A003,12/02/03
    CreditCard:
    100,42323232..., VISA
    100,5234234...., MASTER
    Now how can I get
    custID, Name, Address, OrderID, orderDate, creditCard#, creditCarType
    data in minimum no. of records....
    I think I have made my query clear..
    now please help me guys...
    thanks so much for your help.

    You are right.
    But frankly the actual tables on my database are not customer,orders and creditcards..but I just tried to reproduce the problem with these tables, please ignore that user needs a refund etc situtaion. If the tables were actually order,creditcards etc..it would have been a problem to be considered.
    Can you please help me with the query
    if I have m rows in Order and n rows in CreditCard. I will get m*n records, I looking for max(m,n).
    With the following fields in my query result,
    custID, Name, Address, OrderID, orderDate, creditCard#, creditCarType
    from Customer, Order, CreditCard tables
    Thanks so much for your htlp

Maybe you are looking for