Select only duplicate records

Hi,
I have a table 'test' which has 3 columns - ID, Short_desc and Long_desc.
The sample data for the table is like(fields are comma separated) :
1,AB,Abstract
1,AB,Abolish
2,GM,GoodMorning
3,CD,CompactDisc
3,CD,ChangeDirNow I need to write a query which will only select those distinct rows having duplicate short_desc,i.e., my output will be :
1,AB
3,CDWhat should be the most performant query to fetch the results as in actual scenario I have more than 20 million records in the table. I have tried different combinations but they are running really slow.
Appreciate any help regarding this.
Regards,
Mainak

Hi,
select ID, Short_desc
  from test
group by ID, Short_desc 
having count(1)>1If you have to scan all table, you could use PARALLEL select to speed up your query.

Similar Messages

  • How to select only one record at a time in ALV

    Hi all,
    I have to use ALV report.  Each record on the report output should have a button (or radio button) which will allow the record to be selected.  My requirement is to select only one record at a time.
    please guide me how to proceed further.
    regards
    manish

    hi
    https://www.sdn.sap.com/irj/sdn/wiki?path=/display/snippets/sampleCheckBoxProgram
    Regards
    Pavan

  • Regarding Select query to select only 1000 records in Internal Table.

    Hello Friends,
    Please explain me to how to Select only 1000 records from data base table?
    For Example
    SELECT *  INTO TABLE ITAB                          OR            SELECT * INTO ITAB 
         FROM EKKO                                                                  FROM EKKO
    WHERE EBLEN IN S_EBLEN.                                            WHERE EBLEN IN S_EBLEN
    (Currently i am using)                                                       UP TO 1000 ROWS.
                                                                                    ENDSELECT.  (I do not want to use)
                                                                                    In this case Internal table may be store more then 1000 records. But i want to select first 1000 records.
    Please explain me.
    Regards
    Amit

    Hi,
    TABLES : ekko.
    selection-screen begin of block b1 with frame title text_t01.
    SELECT-OPTIONS: S_EBELN for ekko-EBELN.
    selection-screen end of block b1.
    DATA itab TYPE STANDARD TABLE OF ekko.
    SELECT *
      FROM ekko
      INTO TABLE itab
      UP TO 1000 ROWS
      WHERE EBELN IN S_EBELN.
    Thanks,
    Sri.

  • JDBC: How  to select only those records which contains col1 is NULL

    Hi All,
    In JDBC SELECT scenario.
    I wants to select only those records which contains col1 is NULL.
    I am trying as follows:
    <key>
    <col1 isNull="TRUE" />
    </key>
    but in moni/monitoring i am getting Following Error
    006-12-01 19:35:20 Error Unable to execute statement for table or stored procedure. 'BG_SALARY_SEND_SAP_D' (Structure 'SELECT') due to java.sql.SQLException: FATAL ERROR document format: structure 'SELECT', key element 'key' contains no values
    2006-12-01 19:35:20 Error Exception caught by adapter framework: Error processing request in sax parser: Error when executing statement for table/stored proc. 'BG_SALARY_SEND_SAP_D' (structure 'SELECT'): java.sql.SQLException: FATAL ERROR document format: structure 'SELECT', key element 'key' contains no values
    Please suggest how to do select rows with col1 is null.
    Regards

    Rohan,
    isNull= true is used to make the KEY element not mandatory.
    In your case, if the select query is
    select emp from emptest where empno is null
    , then the datatype will be,
    <root>
    <StatementName>
    <dbTableName action=”SELECT”>
      <table>emptest</table>
    <access>
    <emp></emp>
    </access>
    <key1>
    <b><empno hasQuot="NO">is null</empno></b>
    </key1>
    </dbTableName> 
    </StatementName>
    </root>
    I dont have a DB access to try this, but I think this should work.
    If this doesnt work, then you would need to use SQL_QUERY,
    <root>
    <StatementName>
    <anyName action=” SQL_QUERY”>
    <access>select emp from emptest where empno is null</access>
    </anyName > 
    </StatementName>
    </root>
    http://help.sap.com/saphelp_nw04/helpdata/en/2e/96fd3f2d14e869e10000000a155106/content.htm
    Regards,
    Bhavesh

  • HOW TO SELECT ONLY THOSE RECORDS WHERE NOT AVAILABLE ON SECOND TABLE

    hi
    i have two tables one name is menus and second name is UGroupDetail. Actually i have created it for user role privileges for my application
    USE [LedgerDB]
    GO
    /****** Object: Table [dbo].[Menus] Script Date: 03/28/2015 13:45:27 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    CREATE TABLE [dbo].[Menus](
    [RightID] [int] NOT NULL,
    [RightName] [nvarchar](200) NULL,
    [GroupID] [int] NULL,
    CONSTRAINT [PK_Menus] PRIMARY KEY CLUSTERED
    [RightID] ASC
    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
    ) ON [PRIMARY]
    second table is
    USE [LedgerDB]
    GO
    /****** Object: Table [dbo].[UGroupDetail] Script Date: 03/28/2015 13:46:12 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    CREATE TABLE [dbo].[UGroupDetail](
    [RightID] [int] NOT NULL,
    [RightName] [nvarchar](200) NULL,
    [GroupID] [int] NULL
    ) ON [PRIMARY]
    GO
    ALTER TABLE [dbo].[UGroupDetail] WITH CHECK ADD CONSTRAINT [FK_UGroupDetail_Menus] FOREIGN KEY([RightID])
    REFERENCES [dbo].[Menus] ([RightID])
    ON UPDATE CASCADE
    ON DELETE CASCADE
    GO
    ALTER TABLE [dbo].[UGroupDetail] CHECK CONSTRAINT [FK_UGroupDetail_Menus]
    GO
    ALTER TABLE [dbo].[UGroupDetail] WITH CHECK ADD CONSTRAINT [FK_UGroupDetail_UserGroup] FOREIGN KEY([GroupID])
    REFERENCES [dbo].[UserGroup] ([GroupID])
    ON UPDATE CASCADE
    ON DELETE CASCADE
    GO
    ALTER TABLE [dbo].[UGroupDetail] CHECK CONSTRAINT [FK_UGroupDetail_UserGroup]
    UGroupDetail have many groups as assigned to a new user but Menus table has only default groups which is 90 records
    Menus table is a primary table and UGroupDetail is a Foreign key table
    now i want to combined these tables and want to get only remaining records for each group
    for example i have assigned 5 roles to GroupID 2 and now when i apply select commands the result should be 85 out 90 for GroupID 2
    but i have not idea how to modify select query for get desired result

    I don't really understand the tables. What is GroupID doing in the Menues table? And what does an entry without a RightName mean? Shouldn't that column be NOT NULL?
    The UGroupDetail does not have any primary key. From your description, I would expect the PK to be (RightID, GroupID). But strangely enough, GroupID is nullable. So is RightName, but I think this column is redundant and should be removed.
    Anyway, if I understand your question correctly, you need something like:
    SELECT UG.Name, M.RightName
    FROM   UserGroups UG
    CROSS  JOIN Menus M
    WHERE  NOT EXISTS (SELECT *
                       FROM   UGroupDetail UGD
                       WHERE  UG.GroupID = UGD.GroupID
                         AND  UG.RightID = M.RightID)
    Erland Sommarskog, SQL Server MVP, [email protected]

  • URGENT: Selecting only 25 records at a time from a table

    URGENT !!!!
    Hi,
    Im having a RFC which selects records from a table (say table_A) and depending on these selected records, further processing is done within that RFC.
    Now my problem is, this table_A contains around 200 matching records. Due to this entire logical processing consumes lot of time. Hence my RFC is taking huge time to produce result. (apprx 10 mins).
    Can i select these matching records in batch of 25 and display result for these 25 records??
    I'll give this batch size as input to RFC?
    Do anybody have any idea about how to tackle this situation and reduce response time?
    If u hav any better solution than this then pls pls let me know ASAP..
    Regards,
    Amey

    Amey Mogare  ,
                             Do One thing , create  a new importing parameter in your RFC , say current_trans_id. NOw on the first call pass the initial value for current_trans_id.
    then inside the logic .. change the select to
    select upto 25 rows where trnascation id > current_trans_id.
    next time when u call teh rfc.. send the last selected id as a value for current_trans_id.
    i think you can some how use this logic
    Regards
    Sarath

  • How to Select the duplicate records in the table

    Hi
    SELECT * FROM gin A WHERE A.sale_order_id IN (
    SELECT sale_order_id FROM gin GROUP BY sale_order_id
    HAVING COUNT(sale_order_id)>1)
    AND A.ROWID!=MIN (ROWID))
    ERROR at line 4:
    ORA-00934: group function is not allowed here
    Thanks
    Vikas Singhal

    Try this out
    select *
    from gin a
    where a.rowid > any (select b.rowid
    from gin b
    where a.col1 = b.col1
    and a.col2 = b.col2);
    Regards
    Ozy
    [www.oraclevillage.com]
    Edited by: Ozy on Feb 4, 2009 4:12 AM

  • How can I select the random records in u201Cstep loopu201D.

    Hi, Experts,
    I am using step loop to display the data on screen now I want to select the random records from this step loop display. Like 1st 3rd or 5th record, is there any way to select the records,
    like I did in Table control there was a filed in internal table named marked char length 1, I gave this field name in u201Cw/ SelColumnu201D it fill that field with u2018Xu2019 from where I can get the info about the selected records, in this way I can easily perform the operation on that internal table with the help of that marked field.
    Is there any way to select the records in step loop too ?
    Kind Regards,
    Faisal

    thanks for replay shwetali,
    but i just gave you example of random records with 1st 3rd and 5th my goal is not select only these records. i want to select the random mean any records from the step loop display.
    like we can select from the table control. and when select any record it place 'X' in the given internal table field.
    Thanks and kind Regards,
    Faisal

  • Ignore duplicate records for master data attributes

    dear  experts ,
                   how & where can i  enable "ignore duplicate records" when i am running my DTP to load data
                     to master data attributes.

    Hi Raj
    Suppose you are loading master data to InfoObject and in PSA you have more than one records for Key.
    Let's assume you are loading some attributes of Document NUmber ( 0DOC_NUMBER) and in PSA you have multiple records for same document number. In PSA this is not a problem, as Key for PSA table is technical key and which is different for every record in PSA. But this is a problem for InfoObject attribute table as more than  one records for primary key ( here 0DOC_NUMBER) will create Primary Key consraints in database.
    This issue can be easily avoided by selecting "Handle Duplicate Records" in DTP . You will find this option under *update" tab of DTP.
    Regards
    Anindya

  • Duplicate Records in Transactional Load

    Dear All,
    I have an issue where data is getting loaded from a Write Optimized DSO to another Write Optimized DSO and the DTP is getting failed because of Duplicate Records. It is for a Transactional Load.
    I would be grateful if you could please help me to know how i can handle this situation and reload the DTP again.
    I have tried searching the Forum,but i can see many for Master data loading where i can select Handling Duplicate Records.
    Thanks in Advance...
    Regards,
    Syed

    Hi Ravi,
    Thanks for your reply.
    If we uncheck the option, it would take the duplicate records right.
    In my scenario, data is coming from a Write Optimized DSO to another Write Optimized DSO. Where as in the first DSO the Data Uniqueness is not checked and in the second DSO uniqueness is checked, so it is giving me the duplicate error message.
    I saw around 28 records in the Error Stack. So please let me know, how i can process this error records(Duplicate) as well.
    Many Thanks...
    Regards,
    Syed

  • Identify Duplicate Records

    Post Author: chrise
    CA Forum: Crystal Reports
    I know that Crystal has the ability to identify all distinct records, thereby, getting rid of all duplicate records. However, I need to do the exact opposite and so far have been unsuccessful. Can anyone aid me in creating a report to identify only duplicate records in Crystal?
    Thanks.

    Post Author: SKodidine
    CA Forum: Crystal Reports
    Check out this KBase article.
    Retrieving duplicate records

  • Possible BUG: duplicating a shape layer only duplicates previously selected points - PS CS6

    Unless PS has been updated to make this a feature, i may have found a bug. Now (in CS6 vs. previous versions) when you duplicate a shape layer, if you had previously selected specific points of the shape (for example with the direct selection tool) only those points will be duplicated in the new layer. This is true no matter what tool you are currently using.
    What I did was make a rounded-corner rectangle shape -> then direct selected all points on one side to stretch the rectangle without distorting the rounded corners -> then switched to the move tool so no points were selected anymore and only the layer was selected-> duplicate layer (with the intention of duplicating the whole shape). what i got was just the rounded corners on a new layer.
    It seems the only way to duplicate the shape layer in its entirety is to go back with the direct select tool -> select ALL points of the whole shape -> change to move tool -> dupe layer.
    If that's the intended new functionality, it's a bummer because if you intend to only duplicate certain points, you can already do that while using the direct select tool. Using the move tool, it shows no direct selections and therefore you should be able to duplicate the whole layer.
    Maybe I have some weird default option checked that I'm not familiar with? This is not how any previous versions of PS worked and will add friction to my workflow if this is new.

    Yes, this is an issue with CS6 and the first release of CC.  You have to make sure you deselect all nodes in a path, or you will get the result you describe.  I believe Adobe has made some corrections and improvement in the use of shape layers that will hopefully be released soon.  However, if you're sticking with CS6, you've got to make sure to deselect on Win the esp key works great.

  • Select query-using Union All display duplicate records.

    Hello All Gurus-
    I am using Oracle 9.i
    When i use the following query to fetch the records based on BUILDNUMBERNAME and ASSIGNED_BUILD then i am getting duplicate records -
    select T1.ID FROM Defect T1,statedef T2,repoproject T3
    WHERE T1.STATE=T2.ID AND T1.repoproject = T3.dbid AND T3.name Like 'ABC' AND T1. ASSIGNED_BUILD like '1.4.5.6'
    Union All
    select T1.ID FROM Defect T1,statedef T2,repoproject T3
    WHERE T1.STATE=T2.ID AND T1.repoproject = T3.dbid AND T3.name Like 'ABC' AND T1.BUILDNUMBERNAME like '1.4.5.6'
    How can i use the order by on T1.ID ? When i use the Order by T1.ID then it throws some error.
    Kindly help me in this :(
    Thanks in advance.

    Sorry for not providing all of the details -
    I am using Toad tool to run the query.
    1-When i use the following query -
    Select T1.ID FROM Defect T1,statedef T2,repoproject T3
    WHERE T1.STATE=T2.ID AND T1.repoproject = T3.dbid AND T3.name Like 'ABC' AND T1. ASSIGNED_BUILD like '1.4.5.6' order by T1.ID
    Union All
    select T1.ID FROM Defect T1,statedef T2,repoproject T3
    WHERE T1.STATE=T2.ID AND T1.repoproject = T3.dbid AND T3.name Like 'ABC' AND T1.BUILDNUMBERNAME like '1.4.5.6' order by T1.ID
    ORA-00933: SQL command not properly ended.
    2-If i am not using the T1.ID and run the following query
    Select T1.ID FROM Defect T1,statedef T2,repoproject T3
    WHERE T1.STATE=T2.ID AND T1.repoproject = T3.dbid AND T3.name Like 'ABC' AND T1. ASSIGNED_BUILD like '1.4.5.6'
    Union All
    select T1.ID FROM Defect T1,statedef T2,repoproject T3
    WHERE T1.STATE=T2.ID AND T1.repoproject = T3.dbid AND T3.name Like 'ABC' AND T1.BUILDNUMBERNAME like '1.4.5.6'
    Then it is running fine but it is displaying the duplicate values like -
    00089646
    00087780
    00089148
    00090118
    00090410
    00088503
    00080985
    00084526
    00087108
    00087109
    00087117
    00088778
    00086714
    00079518
    00087780
    00089148
    00090392
    00090393
    00090395
    00090398
    00090401
    00090402
    00090403
    00090406
    00090408
    00088503
    00080985
    00084526
    00087108
    00087109
    00087117
    00088778
    00086714
    00079518

  • Need to return only one record from select statement.

    Hello friends,
    I have a scenerio in which code only want to fetch one value from the SQL statement, but in some cases the statment return more then one row due to which ORA-01422 : Exact fetch return more then one row, error comes.
    Can you suggest me to write a select statement that will handel this. I am using the below mentioned select statement:
    EXECUTE IMMEDIATE
    'SELECT rsdn FROM ' || schema || '.table_name' ||
    ' WHERE a = :1 AND b = :2 AND c IN (32,33,34)'
    INTO v_rsdn USING v_a, v_b;
    One question, Can I use Rownum < 2 in Where clause to restrict the select output to only one record ? Please suggest ?
    Regards,
    Rajat

    Well, if rownum=1 could be a trash answer, it would be an issue since we don't know which record you are interested to. Is it one particular ? Is it only to workaround the issue ? Then you may want to manage some BULK COLLECT or whatever else array to receive all the rows as well.
    What are you doing with the rows returned ?
    Nicolas.

  • Syndication only when records are updated, but ONLY for selected fields

    again with one of my : it's that even possible at all ?
    the case, we have a customer repository where, among other things we add some extra info (classification ABC and similar mainly) to a small percentage of them (around 5 - 10 %)
    and we would like to distribute only those changes, changes in few fields
    of course we load plenty of fields from R3 and other systems, and also we modify records to assign the customers to different business organization that have to look after, this assignments change also very often (it can affect to 30 to 40 % of the customers). All this data does not need to be distributed.
    so in figures (as example to easier understand), weekly base :
    _ 250.000 _ aprox records in MDM
    _ __ 1.000 _ new records every week from source systems
    _ __ 8.000 _ updated records every week from source systems
    _ ______________(yes, big number, some marketing attributes and soft stuff they like to see in MDM)
    _ ____ 100 _ aprox are "enhanced" with data we need to distribute
    _ __ 50.000 _ aprox records are re-assigned or reclassify with data we do NOT need to distribute
    _ ______________(mostly done with assignments and so on that keep changing every week)
    so, even selecting "suppress unchanged records", MDM keeps distributing like 60.000 records, when we only need those 100.
    is any direct way to make this ??
    as a work-around, I have think into a workflow that in a way flags a new field (to_be_distributed) always and only when a user change one of this specific fields. And then filter the distribution for only this field = True. And another workflow that set the mention field to False, just after the distribution is done.
    Crazy idea ??, anything better ??
    (we are in MDM 5.5, if the solution require 7.0, migration plans are in the horizon)
    thanks in advance, everybody

    Hi,
           We had the same scenario where in we have to Syndicate only certain Fields to Legacy...As per your scenario add classification data to your Existing Customer repository. Next steps is to create a map for the classifications data...You write your own conditions in FreeForm search of MDM Syndication. Whenever certain conditions are satisfied, MDM system will syndicate. 
    Next - Option - If you are implementing work flow then create a extra field called Syndicate_Legacy. Syndicate_Legacy should be Flat LookUps .Values should be Syndicate,No Syndicate.  Before end of the WF, you should have  a assignment step. By using assignment change the value to Syndicate or Not syndicate. For this , along with map you should also write a condition in Free form search in syndicator stating that only if Field(Syndicate_Legacy) = Value(Syndicate). I believe these should solve your issue...If not please let me know...
    Thanks
    Ganesh Kotti

Maybe you are looking for

  • MSI 865PE NEO2-V booting problems [Solved]

    Hi.  I've been building a new computer and am seeing some weird stuff. System Specs: -P4 3 GHz Socket 478 -MSI 865PE NEO2-V -V22 http://www.saveateagle.com/865pe-ne...EO2-V&ovtac=CMP -128mb ATI Radeon 9800 pro -120 GB Western Digital -1GB dual channe

  • Java.libary.path  How to use it ?

    I wanted to access the windows registry from my java program. so i downloaded a jni package and set the classpath to it. i now get java.lang.Unsatisfiedlinkerror.no ICE_JNIRegistry in java.library.path ? How to rectify this ?

  • What are the tools to create a digital magazine for ipad version and how can be place it in newsstand?

    Hello.. "what are the tools to create a digital magazine for ipad version and how can be place it in newsstand?" I am very tired after done a week of R&D on this issue.. But i doesn't get any fair solution for this one.. I hope this is best option to

  • How to change field size using SQL against an oracle Database

    I am an admitted novice user, looking to become more proficient. I have a field in a table that I need to expand the field size. The table is called Inquiries. The data type is text. The current Field Size is 10. I want to increase it, to either the

  • Temp Tables Space error

    Hi Friends, We are using two fact tables in a query along with three master tables. We have tried to increase the table space for temp several times. But due to loads of data increasing in the facts We are struck back by the error could not increase