Del duplicate with different condition in a table.

Hi All,
In my table, there are duplicate records. I need to delete duplicate records based on below 3 conditions.
Table : ABC
===========
DEPTID
DEPTNAME
Here, we identify whether records are duplicate or not based on DEPTID, but we need to consider DEPTNAME while deleting.
Conditions: 1
=============
Lets say, there are 3 records for DEPTID = 200, out of that, one record contains DEPTNAME and remaining 2 records are NULL, then remove records with DEPTNAME null and keep one with DEPTNAME.
Condition: 2
============
Lets say, out of 4 records (duplicate with DEPTID 200), 2 records have DEPTNAME and 2 records have DEPTNAME NULL, keep any one records which have DEPTNAME and remove remaining 3 records.
Condition: 3
============
Lets say, all 5 records (duplicate with DEPTID 200), have DEPTNAME NULL. Keep only 1 record and delete remaining duplicate.
Can someone help me how to achive this?

DELETE FROM abc
      WHERE ROWID NOT IN (
               SELECT r
                 FROM (SELECT ROWID r, deptid, deptname,
                              ROW_NUMBER () OVER (PARTITION BY deptid ORDER BY deptname DESC NULLS LAST)
                                                                           rn
                         FROM abc)
                WHERE rn = 1)Regards,
Mahesh Kaila

Similar Messages

  • Search for Duplicates with different titles

    Some of us ill organized users have thousands and even tens of thousands of pictures scanned in from old albums, 35mm slides, and shoe boxes full of loose pictures. The result is many duplicates with different names. In Elements one could search on 'similar photos' or some such nomenclature and it did fairly good. How is it possible that an organizer in Photoshop Elements can have a superior tagging and search system to that in lightroom. I realize Lightroom does a lot more, but you have come so close to the good things in Elements why not include them in version 1.2?
    I asked about this in the forum and got some good answers, but basically told if I want to search on photo based color data, I need to use a program other than Adobe. Hope Adobe fixes that, it would be a great service to lots of us dis- or ill- organized people.
    I love Lightroom, but sure hope for some real improvements. Talk to your buddies in Elements.
    Jack

    here is one way to find all matches first and then you can add a fine search/separation if there is more than one match
    depending on the size of the sorted array it might be faster if you search for the first match and than look if the next still matches ...
    Greetings from Germany
    Henrik
    LV since v3.1
    “ground” is a convenient fantasy
    '˙˙˙˙uıɐƃɐ lɐıp puɐ °06 ǝuoɥd ɹnoʎ uɹnʇ ǝsɐǝld 'ʎɹɐuıƃɐɯı sı pǝlɐıp ǝʌɐɥ noʎ ɹǝqɯnu ǝɥʇ'
    Attachments:
    find all matches.vi ‏11 KB

  • 2 for all entries with different condition

    Hi
    i have an internal 2 internal table which have the following field
    ITAB1 : Stock category, plant, storage location , SKU code   (those value are given though flat file)
    ITAB2 : Grid value , meterial NO, SKU code  (those values are determine through a FM where we export the SKU code and it will retreive the matnr and grid value in an ITAB2)
    I have to do select FROM database MCHB
    with the condition Grid value , material NO , Stock category, plant, storage location
    Note that gris value and matnr are found in two different internal table i was thinking of doing for all entries but
    is it possible to do for all entries from 2 internal table
    SELECT FOROM MCHB
    FOR ALL ENTRIES in ITAB1
    FOR ALL ENTRIES in ITAB2
    WHERE
    grid value = itab2-gridvalue
    matnr = itab2-matnr
    stock cat = itab1-stock cat
    plant = itab1-plant
    storage location = itab1-storage location
    Please help on how to tackle this?

    Hi,
    You have to create a new third internal table with the fields matnr, grid value, stock category, plant and storage location....
    Then process the itab1 and get the process the itab2 for the corresponding SKU Code (which I believe is the common field for both of the internal tables) and then populate the third internal table itab3...
    Then use the itab3 for the FOR ALL ENTRIES.
    Thanks
    Naren

  • Two Fact tables with Different set of Dimension Tables

    Here is my scenario:
    I got two fact tables: X and Y (actually, they are the same tables, but with different level of data)
    and four dimension tables: A, B, C, D
    X joins relationship to all dimensions (A, B, C, D).
    Y joins relationship to only A, B, C, but no D.
    When I select dimension A, B and C together with fact tables X and Y in BI Answer, result is displayed and compared.
    However, if I select dimension D together with fact tables X and Y, only data from fact table X is displayed. There is no result displayed for fact table Y. I know that this is because fact table Y does not join to dimension D.
    If the above relationship unchanged, how can I display both X and Y's result in BI Answer when dimension D is selected?

    Thanks for all your replies.
    Actually, I've tried the solutions you guys mentioned. Generally speaking, the result should be displayed. However, my scenario is a little bit tricky.
    table Y's figures are not the aggregation of table X for D dimension. Instead, table Y's figures include not only D dimension total, but also others (others do not mean A, B, C dimension). For example, table Y stores all food's figure, while table X stores only drink's figure. D dimension is only about drink's detail. In my scenario, other foods' figure is not provided.
    So, even if I set D dimension to all/total for table X, table X's result is still not the same as table Y.
    Indeed, table Y does not have a column key to join to D dimension's key. So, if I select D dimension and table Y's measures at the same time in BI Answer, result returns no data. Hence, I can't compare table X and table Y's results with selection of D dimension.
    Is there any solution to solve this problem?
    Edited by: TomChan on Jun 3, 2009 9:36 AM

  • Collecting same data with different value into a table

    Hi,
    Can you people help me with this problem.
    I have an internal table with different data e.g :
    A    2
    B    1
    C    3
    A    1
    D    7
    B    5
    Now i want to put the values of A,B,C,D into another internal table with some other calculation done.
    But when i am using READ Table with KEY my second internal table is getting filled with A=2 and the second A=2 as well instead of 1.I guess because it is reading the first record only as its finding A first.
    How will i fix this one.
    Kind Regards,

    >
    Prasenjit Sengupta wrote:
    > Hi,
    >
    > Can you people help me with this problem.
    > I have an internal table with different data e.g :
    > A    2
    > B    1
    > C    3
    > A    1
    > D    7
    > B    5
    > Now i want to put the values of A,B,C,D into another internal table with some other calculation done.
    > But when i am using READ Table with KEY my second internal table is getting filled with A=2 and the second A=2 as well instead of 1.I guess because it is reading the first record only as its finding A first.
    > How will i fix this one.
    >
    > Kind Regards,
    Can you tell me the exact requirement of yours?

  • Selecting data from single table with different condition in single query

    Hi everybody...
    I have one table with col1, col2, col3, col4, col5... as columns.
    I want to select col1, col2, col3 with condition (x=y and a=b and c=d)
    I want to select col4, col5 with condition (x=y and a=b and m=n )
    in single query...
    Thanx for ur help

    Given this data set...
    SQL> select * from oddity
      2  /
          COL1       COL2       COL3       COL4       COL5 A X C M
             1          2          3          4          5 B Y   M
             1          2          3          4          5 A Y C N
             1          2          3          4          5 A Y D M
             1          2          3          4          5 A Y D N
             1          2          3          4          5 B Y D N
             1          2          3          4          5 B Y D U
    6 rows selected.
    SQL>The following query meets the requirements. Of course, the requirements as stated are incomplete. I ahave assumed that we select all five columns if C=D andM=N.
    SQL> SELECT decode(c, 'D', col1, '0') AS col1
      2         , decode(c, 'D', col2, '0') AS col2
      3         , decode(c, 'D', col3, '0') AS col3
      4          , decode(m, 'N', col4, '-8') AS col4
      5           , decode(m, 'N', col5, '-8') AS col5
      6  FROM oddity
      7  WHERE a = 'B'
      8  AND  x = 'Y'
      9  /
          COL1       COL2       COL3       COL4       COL5
             0          0          0         -8         -8
             1          2          3          4          5
             1          2          3         -8         -8
    SQL> Cheers, APC

  • How do I combine my iphone contact list with my laptop pc contact list?  And how does it handle duplicates with different information?

    How do I combine my iphone contact list with my laptop pc contact list? And how does it handle duplicates that have different information?
    How do I merge my iphone calendar appointments/alerts with my laptop pc calendar appointments/alerts?  And how does it handle duplicates?
    I do not need anything to change on my email that is working fine on both.

        gspielman,
    Help has arrived to assist you with getting those contacts on both your devices. The Verizon cloud service is definitely a great tool to use and you can also use Apple iCloud as well. When you sign into the Verizon cloud on your iPad does it give an option or message to restore?
    CandiceH_VZW
    Follow us on Twitter @VZWSupport

  • Want to update a column with  different column of same table

    I have a table TEST_CDR which is having 250 millions records also having partition by hash.
    there are two column in this table ID and CDR_ID want to update ID in CDR_ID but it take too much time like 24 hours or more.
    please suggest me a simple way.

    Hi,
    You can try this. but be careful about your backups and go through CTAS,nologging and parallel concepts...
    Please refer this link.
    http://www.dba-oracle.com/t_fast_batch_updates_ctas.htm
    http://www.dba-oracle.com/t_nologging_append.htm
    http://www.dba-oracle.com/t_efficient_update_sql_dml_tips.htm
    http://eriglen.blogspot.in/2011/08/ctas-create-table-as-select-with.html
    1.CTAS with nologging and parallel..
    SQL> create table test_cdr_1(id,cdr_id) nologging parallel as select id,id from test_cdr;
    2.rebuild indexes, triggers and constraints to test_cdr_1
    3.rename test_cdr to bkup_test_cdr;
    4.rename test_cdr_1 to test_cdr;
    Regards,
    ragunath.

  • How to create summation column with different measures of fact table

    If I have a salary fact table with columns MONTHID | BASIC-SALARY | TRAVEL-ALLOWANCE
    and in Deski, I drag all the three columns to form a horizontal table
    then is it possible to create a summation column to show total salary?
    I don;t want to create a variable because in that case the formula need to be changed everytime there is a new allowance.
    regards,
    binayak

    Hello Binayak,
    as you refer to Deski I recommend to post this query to the [BusinessObjects Desktop Intelligence|SAP BusinessObjects Desktop Intelligence; forum.
    This forum is dedicated to topics related to the creation and design of Desktop Intelligence documents such as universe connectivity, prompts, charting, formatting, filter, and formulas.It is monitored by qualified technicians and you will get a faster response there.
    Also, all Desktop Intelligence queries remain in one place and thus can be easily searched in one place.
    Best regards,
    Falk

  • BRFplus: Functions with different Signatures for Decision Table

    Hi all,
    I am new to BRFplus and attempting to do some prototyping with it.
    I have created a Decision Table which defines valid combinations of width and thickness for a product.  The product id, width and thickness are the query columns; the results column is a boolean value that indicates if the combination is valid.
    I have successfuly created a Function that given product id, width and thickness returns whether the combination is valid.
    I now want to create another Function that given product id and width only (but not thickness) refers to the same Decision Table and returns whether the product id and width combination is valid.
    Is this possible ?  If so, how do I go about it ??
    I tried creating a new Function with this signature but I just get an error "Assigned expression uses Element WIDTH/Width which is not in the context ".
    Any comments or suggestions appreciated.
    Thanks,
    Grogan

    Hi, Grogan
    When you're talking about a Functio  you men a BRF+ function, don`t you?
    So, if you go to this function there is a tab called "Signature" , the second one....
    Have you tried to add your Element WIDTH to the Function signature and test again ?  
    May be the long text of the error message could help you as well.....
    Kind regards

  • MVC Event Handling with different rows of same table view

    Hello friends,
    I have a tableview with some rows.I have some columns in the tableview.First column contains the drop down list box and other columns are output fields.
    I am allready able to populate the columns according to the selection of a value in the drop down listbox of the same row.
    In the layout of view for the selectionmode attribute of tableview i have given 'lineedit'.
    In the do_handle_event i am also able to get the current selected row of the tableview.
    DATA: tv_data TYPE REF TO cl_htmlb_event_tableview.
    selection = tv_data->selectedrowindex.
    Scenario:I have selected the first row then i am selecting a value in the dropdown and able to populate their corresponding value in the corresponding output field of same row.
    So the first row has the selected value in drop down listbox also the corresponding outputfield of same row also has the value.This i am doing by inserting it to the final internal table for the tableview according to currrent selected row .
    Now i am going to select the second row.then i am selecting someother value in the dropdown listbox of the second row and filling the other columns correspondigly.I am able to do this for the secondrow.What i now need to do is i also want to see the first row with slected values correspondingly when the final view comes.ie i need both rows with corresponding values.
    Similarly when selecting third row and other rows so on.
    how to do this?
    Thanks & Regards,
    Renju.

    Hi Renju,
    Try using MULTILINEDIT - this is used when you want to edit multiple rows all at once.
    Cheers

  • Group by same column with different conditions

    Hi All,
    I have the following SQL statement
    select Sum(Total), Region, Code from table_A group by Region, Code
    Code has distinct values of 1 to 10 for each Region.
    Is it possible to group by Region, Code < 5 and Code > 5.

    Here is a solution which I have but wanted to see if there is any other way to do it.
    select Sum(Total), Region,'code<5' as Code from table_A group by Region, Code having code < 5
    union
    select Sum(Total), Region,'code>5' as Code from table_A group by Region, Code having code > 5

  • Different conditions for different columns

    Hi,
    I have two tables and both have 3 common columns. I have to write a query joining the two tables and get different columns with different conditions.
    For e.g., I have the tables test and test1.
    create table test (a1 varchar(10), a2 varchar(10), a3 varchar(10), a4 date, a5 number, a6 number, a7 number, a8 number);
    create table test1 (a1 varchar(10), a2 varchar(10), a3 varchar(10));
    insert into test1 values('abc', 'a', 'z');
    insert into test1 values('xyz', 'b', 'y');
    insert into test values('abc', 'a', 'x', trunc(sysdate,'MM'), 100, 200, 300, 400);
    insert into test values('abc', 'b', 'z', trunc(sysdate,'MM'), 567, 4778, 4234, 6767);
    insert into test values('xyz', 'a', 'y', trunc(sysdate,'MM'), 5467, 2134, 5678, 8332);
    insert into test values('xyz', 'b', 'z', trunc(sysdate,'MM'), 3534, 744, 678547, 46);
    insert into test values('abc', 'a', 'x', trunc(add_months(sysdate,-1),'MM'), 700, 800, 900, 600);
    insert into test values('abc', 'b', 'z', trunc(add_months(sysdate,-1),'MM'), 565477, 474578, 4456234, 226767);
    insert into test values('xyz', 'a', 'y', trunc(add_months(sysdate,-1),'MM'), 235467, 2342134, 255678, 258332);
    insert into test values('xyz', 'b', 'z', trunc(add_months(sysdate,-1),'MM'), 324534, 25744, 678547, 78846);
    select * from test1;
    A1     A2     A3
    abc     a     z
    xyz     b     y
    select * from test;
    A1     A2     A3     A4                     A5     A6     A7     A8
    abc     a     x     05/01/2010 00:00:00     100     200     300     400
    abc     b     z     05/01/2010 00:00:00     567     4,778     4,234     6,767
    xyz     a     y     05/01/2010 00:00:00     5,467     2,134     5,678     8,332
    xyz     b     z     05/01/2010 00:00:00     3,534     744     678,547     46
    abc     a     x     04/01/2010 00:00:00     700     800     900     600
    abc     b     z     04/01/2010 00:00:00     565,477     474,578     4,456,234     226,767
    xyz     a     y     04/01/2010 00:00:00     235,467     2,342,134     255,678     258,332
    xyz     b     z     04/01/2010 00:00:00     324,534     25,744     678,547     78,846I have to write a query to get values for columns a1, a4, a5, a6, a7 and a8. For each distinct month fro mthe column a4, the values for columns a1, a4 a5 and a6 should be based on the condition test1.a1=test.a1 and test1.a2=test.a2. The condition for columns a7 and a8 should be test1.a1=test.a1 and test1.a3=test.a3.
    How can I do this?
    Thanks,
    Machaan

    remove the 4th join and only duplicate test;
    SQL> ed
    Wrote file afiedt.buf
      1  select distinct
      2  case
      3          when t11a1 is null then
      4            t12a1
      5          else
      6            t11a1
      7        end as a1
      8        ,case
      9          when t11a4 is null then
    10            t12a4
    11          else
    12            t11a4
    13         end as a4
    14        ,case
    15          when t11a5 is null then
    16            t12a5
    17          else
    18            t11a5
    19         end as a5
    20  from (
    21        select t11.a1 as t11a1
    22              ,t11.a2 as t11a2
    23              ,t11.a3 as t11a3
    24              ,t11.a4 as t11a4
    25              ,t11.a5 as t11a5
    26              ,t11.a6 as t11a6
    27              ,t11.a7 as t11a7
    28              ,t11.a8 as t11a8
    29              ,t12.a1 as t12a1
    30              ,t12.a2 as t12a2
    31              ,t12.a3 as t12a3
    32              ,t12.a4 as t12a4
    33              ,t12.a5 as t12a5
    34              ,t12.a6 as t12a6
    35              ,t12.a7 as t12a7
    36              ,t12.a8 as t12a8
    37        from test1 t1
    38            ,test  t11
    39            ,test  t12
    40        where t1.a1 = t11.a1
    41        and   t1.a2 = t11.a2
    42        and   t1.a3 = t12.a3
    43* )
    SQL>
    SQL> /
    A1         A4                A5
    xyz        01-APR-10     324534
    xyz        01-MAY-10       3534
    abc        01-APR-10        700
    abc        01-MAY-10        100

  • 2 same surrogate keys with different filter conditions in one report

    how do we put 2 same sr keys with different filter conditions in one single report??
    for example, we have to get the 'count' for tm_sr_key:
    1. count(tm_sr_key) where past_due_flag = Y
    2. count(tm_sr_key) where past_due_flag = Y and N
    to be displayed in one single report.
    it happens that both sr_keys will display the same measure (which is the 1st filter conditions)
    and the filter under criteria tab in anwer will show as :
    tm_sr_key where {filter condition 1}
    AND
    tm_sr_key where {filter condition 2}
    instead of :
    tm_sr_key where {filter condition 1} for 1st measure
    tm_sr_key where {filter condition 2} for 2nd measure
    d only option i could think right now is to duplicate the tm_sr_key data in the same table but with different name say, tm_sr_key_2..
    kindly pls help.
    thanx

    i'm sorry, not really understand.
    could you pls explain a bit more about the filter column? how do we do it? coz i'm really new in this tool.
    r u talking about editing the filter located under the column on the right side of the OBIEE answers?
    or is it by editing the 'edit column formula' for required column; that is by replacing the 'column formula' expression with this:
    FILTER(EXPS_FACT.FAC_SR_KEY USING EXPS_FACT.PAST_DUE_FLAG = 'Y') <----if it is like this, i tried it already & its giving me an error message..
    thanx.
    Edited by: rezza.nasha on May 28, 2009 1:26 AM

  • Not able to color different rows with different colors in a column of table

    Hi,
    I am trying to to display different rows with different colors in a column of the table based on some decode condition.
    I have gone through the following threads :
    Can we colour the rows in the column of a table
    Changing Color of a value in a column
    This is what i have done :
    1.Added the following code to custom.xss(changed the name to Custom.xss as suggested in one of the above threads) --- in path ---- jdev\myhtml\OA_HTML\cabo\styles
    <style selector=".1">
    <includeStyle name="DefaultFontFamily"/>
    <property name="font-size">11pt</property>
    <property name="font-weight">Bolder</property>
    <property name="color">#008000</property>
    <property name="text-indent">3px</property>
    </style>
    <style selector=".2">
    <includeStyle name="DefaultFontFamily"/>
    <property name="font-size">11pt</property>
    <property name="font-weight">Bolder</property>
    <property name="color">#FFFF00</property>
    <property name="text-indent">3px</property>
    </style>
    2. Sql query of the VO is :
    select comments,role ,decode(role,'REQUESTER','1','2') Colorattr from xxat_sars_action_history where request_id = :1 and event_name = :2 and action_code <> 'PENDING'
    order by sequence_num desc
    3. Coded the following in the process request of the controller:
    OATableBean table = (OATableBean)webBean.findIndexedChildRecursive("CommentsTB");
    OAMessageStyledTextBean roleBN = (OAMessageStyledTextBean)webBean.findIndexedChildRecursive("role");
    OADataBoundValueViewObject cssjob = new OADataBoundValueViewObject(roleBN,"Colorattr");
    roleBN.setAttributeValue(oracle.cabo.ui.UIConstants.STYLE_CLASS_ATTR, cssjob);
    where 1 and 2 form the colors ( i have even tried with 'Red' and 'Yellow'...as it was not working replaced with 1 and 2)
    4.The query returns data fine with corresponding 1 and 2 values.
    But different colors are not getting reflecting on to the UI.
    I am testing this on my local jdev.
    Please do let me know if i am missing something.
    Thanks ,
    Sushma.

    Any Clues please.....
    Thanks,
    Sushma.

Maybe you are looking for

  • How do I use a variable within a sql statement

    I am trying to use a local variable within an open SQL step but I keep getting an error. My sql command looks like this "SELECT BoardDetailID FROM BoardDetails WHERE SerialNumber = " +  locals.CurrentSerialNo If I replace the locals.CurrentSerialNo w

  • Audio Problem Front Row DVD

    Hi: Playing a DVD via front row and through a tv, the sound was going up and down, tested it with another dvd and it was the same. Could be it the cabel which is Philex SLx Gold 3.5mm jack to 2 Phono Personal Audio Lead? BTW sound playing music throu

  • What command can I run to see what ports are being used?

    I am trying to connect to citrix and I am receiving a message saying port 999 already in use. How can I fix this? Thanks, JS

  • Form text automatically centers in block; how to change?

    I've created an invoice form in InDesign for a client. I am trying to make this into a pdf form so that the client can just fill in the middle of the page. I've created a text field, but when I test this the type appears in the middle of the block in

  • Can you upgrade from LP8 (Studio) to LP9 and still use LP8 on the same mac

    I love the idea of upgrading Logic However, i've been burned so many times by shabby developers (apple included) releasing software that isn't fully operational until at least 4 months after the relase date and not being able to work on projects due