Get only the first row for duplicate data

Hello,
I have the following situation...
I have a table called employees with column (re, name, function) where "re" is the primary key.
I have to import data inside this table using an xml file, the problem is that some employees can be repeated inside this xml, that means, I'll have repeated "re"'s, and this columns is primary key of my table.
To workaround, I've created a table called employees_tmp that has the same structed as employees, but without the constraint of primary key, on this way I can import the xml data inside the table employees_tmp.
What I need now is copy the data from employees_tmp to employess, but for the cases where "re" is repeated, I just want to copy the first row found.
Just an example:
EMPLOYEES_TMP
RE NAME FUNCTION
0987 GABRIEL ANALYST
0987 GABRIEL MANAGER
0978 RANIERI ANALYST
0875 RICHARD VICE-PRESIDENT
I want to copy the data to make employees looks like
EMPLOYEES
RE NAME FUNCTION
0987 GABRIEL ANALYST
0978 RANIERI ANALYST
0875 RICHARD VICE-PRESIDENT
How could I do this?
I really appreciate any help.
Thanks

Try,
SELECT re, NAME, FUNCTION
  FROM (SELECT re,
               NAME,
               FUNCTION,
               ROW_NUMBER () OVER (PARTITION BY re ORDER BY NAME) rn
          FROM employees_tmp)
WHERE rn = 1G.

Similar Messages

  • Getting the first row for each group

    Hi Everyone,
    I have a query which returns a number of rows, all of which are valid. What I need to do is to get the first row for each group and work with those records.
    For example ...
    client flight startairport destairport stops
    A fl123 LGW BKK 2
    A fl124 LHR BKK 5
    B fl432 LGW XYZ 7
    B fl432 MAN ABC 8
    .... etc.
    I would need to return one row for Client A and one row for Client B (etc.) but find that I can't use the MIN function because it would return the MIN value for each column (i.e. mix up the rows). I also can use the rownum=1 because this would only return one row rather than one row per group (i.e. per client).
    I have been investigating and most postings seem to say that it needs a second query to look up the first row for each grouping. This is a solution which would not really be practical because my query is already quite complex and incorporating duplicate subqueries would just make the whole thing much to cumbersome.
    So what I really new is a "MIN by group" or a "TOP by group" or a "ROWNUM=1 by group" function.
    Can anyone help me with this? I'm sure that there must be a command to handle this.
    Regards and any thanks,
    Alan Searle
    Cologne, Germany

    Something like this:
    select *
    from (
       select table1.*
       row_number() over (partition by col1, col2 order by col3, col4) rn
       from table1
    where rn = 1In the "partition by" clause you place what you normally would "group by".
    In the "order by" clause you define which will have row_number = 1.
    Edit:
    PS. The [url http://download.oracle.com/docs/cd/E11882_01/server.112/e17118/functions004.htm#i81407]docs have more examples on using analytical functions ;-)
    Edited by: Kim Berg Hansen on Sep 16, 2011 10:46 AM

  • How to get only the first level of nodes for a subform?

    How can we get only the first level of nodes of a subform?
    For ex:
    Form1
         SubForm1
              Text1
              Text2
              RadioButton1
         SubForm2
              Text1
              Text2
              RadioButton1
         SubForm3
              Text1
              Text2
                   SubForm31
                        RadioButton1
    In this heirarchy if we give Form1.nodes will refer to all nodes under the Form1 (SubForm1,Test1,Text2,RadioButton1,SubForm2,...SubForm31, RadioButton1 etc..)
    But is there any way that we can access only the first level of nodes of Form1 ie can we get only (SubForm1,SubForm2,SubForm3) for Form1 in any Way..?
    Thanks.

    Two ways .....
    1. Use Javascript E4X instead ...there are nice functions for getting children of parents.
    2. Cycle through all of the form1.nodes and look for objects that have a className of "subform". For loops are useful for this task.
    Make sense?
    Paul

  • How to get only the first result in extract function

    do you know how to get only the first element of the function extract.
    v_result := p_response.doc.extract('//'||p_name||'/child::text()').getstringval();
    if i have 5 responses like '100','100',100','200','200' e get '100100100200200' and i want only '100'.
    thanks in advance

    Two ways .....
    1. Use Javascript E4X instead ...there are nice functions for getting children of parents.
    2. Cycle through all of the form1.nodes and look for objects that have a className of "subform". For loops are useful for this task.
    Make sense?
    Paul

  • How to get only the changed rows in h:dataTable

    Hi,
    I am very new in jsf technology.
    For our application, I need to process only the changed rows in the jsf datatable in managed bean.
    User may also enter new rows.We have to consider this also.
    Pls post ur suggession as soon as possible.This is urgent.This will be best if someone can post me some code snippets.
    Thanks
    -S

    As klejs said, set the valueChangeListener attribute to each of the input fields. Have a method in your backing bean which would
    1) get the index from the component id
    2) get the object and the above index from ArrayList
    3) check if the old Value is different from the new value. If yes, set some boolean flag in that object to true indicating that the row is modified.
    Sample code below. Please feel free to add checks if you need.
         public void updateDirtyFlag(ValueChangeEvent valueChangeEvent){
             if(valueChangeEvent.getOldValue()==null && valueChangeEvent.getNewValue()==null){
                     return;
             if(valueChangeEvent.getComponent().getId()==null){
                 return;
          //Extract the index from the component id in the getId method
             int idVal=getId(valueChangeEvent.getComponent().getClientId(FacesContext.getCurrentInstance()));
             ArrayList dataList=getData(); // data from session or request scope
              if((valueChangeEvent.getOldValue()==null && valueChangeEvent.getNewValue()!=null)        
                     || (valueChangeEvent.getOldValue()!=null && valueChangeEvent.getNewValue()==null)){
                 if(dataList!=null && idVal<dataList.size() && idVal>-1){
                     YourBaseValueObject pojo=(YourBaseValueObject)dataList.get(idVal);
                     pojo.setUpdateFlag(true);
             else if(valueChangeEvent.getOldValue()!=null && valueChangeEvent.getNewValue()!=null && !valueChangeEvent.getOldValue().equals(valueChangeEvent.getNewValue())){
                 if(dataList!=null && idVal<dataList.size() && idVal>-1){
                     YourBaseValueObject pojo=(YourBaseValueObject)dataList.get(idVal);
                     pojo.setUpdateFlag(true);
         }HTH.
    Karthik

  • How do I set only the first row of a DataGrid as the selected row?

    I have a "Go" button on a search form that fetches data into an already data bound grid.  After the data is fetched, I want to make the first row in the Datagrid the selected row, as if the user clicked on it.  If the result set is empty, I don't want the code to crash.  (I only want one row to be able to be selected at a time)
                protected function btnGo_clickHandler(event:MouseEvent):void
                    getSBJsResult.token = baa_data_svc.getSBJs(cmbSrch.text);
                    grdSBJs. //  ?????  What goes here to select the first row?

    This should do it.
    If this post answered your question or helped, please mark it as such.
    if(myDataGrid.dataProvider.length > 0){
      myDataGrid.selectedIndex = 0;

  • af:table, only the first row of the table is effect

    Hi experts,
    I have an issue about using the <af:table, needs your help:
    1.The default selected line is the first line of the table(This should be ok).
    2.Only the first line can react to my manipulate, such as select one line and click delete button.
    3.While choosing the other line-->click the command button, the page will be refreshed and the selected one will turned to the first line. (Now the selected row, will be the first row). And will do nothing ,and has no action with the command button.
    I have an page OVS_Server.jspx, parts of it is :
    <af:table value="#{backVS.serverList}"
    var="row" rows="20"
    emptyText="#{globalRes['ovs.site.noRows']}"
    binding="#{backing_app_broker_OVS_Server.serverListTable}"
    id="serverListTable" width="100%"
    partialTriggers="poll1 commandButton_refresh commandButton_searchServer"
    selectionListener="#{backing_app_broker_OVS_Server.onSelect}">
    <f:facet name="selection">
    <af:tableSelectOne text="#{globalRes['ovs.site.selectAnd']}" autoSubmit="true"
    id="tableSelectOne" required="false">
    <af:commandButton text="#{globalRes['ovs.site.server.poweroff']}"
    id="commandButton_powerOff"
    action="#{backing_app_broker_OVS_Server.powerOffAction}"
    partialTriggers="tableSelectOne"
    disabled="#{backing_app_broker_OVS_Server.unreachableServer}"
    />
    <af:commandButton text="#{globalRes['ovs.site.edit']}"
    id="commandButton_edit"
    action="#{backing_app_broker_OVS_Server.editAction}"
    />
    <af:commandButton text="#{globalRes['ovs.site.delete']}"
    id="commandButton_delete"
    action="#{backing_app_broker_OVS_Server.deleteAction}"
    />
    </f:facet>
    <af:column sortProperty="ip" sortable="true"
    headerText="#{globalRes['ovs.site.serverHost2']}"
    id="column_ip">
    <af:commandLink text="#{row.ip}"
    id="commandLink_ip"
    shortDesc="#{globalRes['ovs.site.viewUpdateDetails']}"
    action="#{backing_app_broker_OVS_Server.viewAction}"
    immediate="true"/>
    </af:column>
    <af:column sortProperty="serverName" sortable="true"
    headerText="#{globalRes['ovs.site.serverName']}"
    id="column_serverName">
    <af:outputText value="#{row.serverName}"/>
    </af:column>
    </af:table>
    One JavaBean OVS_Server.java,and part of it is :
    public class OVS_Server {
    private CoreTable serverListTable;
    private VirtualServer selectedServer;
    public void onSelect(SelectionEvent selectionEvent) {
    selectedServer = (VirtualServer)serverListTable.getSelectedRowData();
    public String deleteAction(){
    if (selectedServer!=null) {
    deleteServerOper.execute();
    return "deleteServer";
    Would anyone show some lights on it?
    Thank you very much.

    Thank you for your reply!
    But the example you mentioned also has the issue like one of the comments :
    "Hi, on selecting the first row it displays the correct value, when navigating to another row still it displays the old value and not fetching the new selected row, actually I can see this on your sample screen shots... is there any way we can fix??"
    Is there any resolution?

  • Only the first page for a particular site prints. All other sites are fine.

    I'm running Firefox 10.0.2 on Windows 7 SP1 and when I try to print the web page of the affected URL ( http://windows.microsoft.com/en-US/windows-vista/Connect-to-another-computer-using-Remote-Desktop-Connection ), only the first page is printed. It prints fine in IE 9. I tried printing in safe mode and it still only prints the first page. I only tried printing it once, after that I used print preview alone. I used print preview on a dozen other sites and it works fine. By the way, on the web page I'm trying to print you must "Show All" at the bottom to expand all of the text. It's just this one web page. Can someone else with a similar setup try print preview on this page for me? I just want to know. I printed it using IE. Interestingly, if you scale the print preview down enough, all of the text shows up. Thanks...

    Well, I've made a little progress. I saved the web page source locally and then added the following HTML snippet to the <head> section:
    <style type="text/css">
    div
    page-break-before:always;
    </style>
    When I display this, the "Show all" does not work, but the page text is still long enough to do "Print Preview" and expect more than one page. The result is a blank first page (expected) and then ALL of the page text is printed on the next two pages.
    But I think you are correct "the-edmeister" in saying that Firefox may have a problem when the DIV tag spans more than one page. The reason is that the third page only contains the footer, so I can't say for sure if the whole DIV block was printed. But at least the footer did show up this time.
    If I can get the "Show all" block to expand then maybe that question will be answered. Any thoughts?

  • Why would only the first line of my data set txt file work?

    Hi -
    I had a lot of success using variables and external data sets until today.
    I have an external text file that I have imported as a data set (Image/Variables/Data Sets/Import...).  All of the variables have been defined and confirmed (at least PSD hasn't told me it can't find something which is the typical error msg.)
    This external text file, with the extension ".txt" has 12 lines on it, each line is 7 comma separated values, and each line is ending in a carriage return.
    YESTERDAY when I used File/Export/Export Data Set as Files... the procedure went beautifully for the 8 times I used it.  TODAY I only get the first of the 12 lines completed and then the export stops.  There are no error messages or other signs that Photoshop has choked on something so I guess something is wrong with my text file... BUT WHAT??
    Any insight on any step in this would be helpful.  You all know that if I'm using this feature it's because I have TONS of repetition ahead of me if it doesn't work.
    TIA your expertise,
    JL

    Fixed it!
    When Exporting as Data sets as files... the step I missed was to select "All Data Sets" from the Data Set drop down.
    Thanks all.
    JL

  • How can I get only the dual rows?

    Dear gurus,
    I want to retrieve the rows that are dual in my SQL.
    select grb.num_matricula
    from gb_ficha_financ_assistido gff,
    gb_rubricas_previdencial grp,
    gb_recebedor_beneficio grb
    where gff.cd_rubrica = grp.cd_rubrica
    and (gff.cd_fundacao = grb.cd_fundacao
    and gff.seq_recebedor = grb.seq_recebedor)
    and grp.id_rub_suplementacao = 'S'
    and gff.dt_referencia = '01/12/2004'
    group by grb.num_matricula
    The query above return 1414 rows...
    But when I execute the query below I recived 1430 rows. The only modification is the column cod_entid that was add.
    select grb.num_matricula matricula ,grb.cod_entid
    from gb_ficha_financ_assistido gff, gb_rubricas_previdencial grp,
    gb_recebedor_beneficio grb
    where gff.cd_rubrica = grp.cd_rubrica
    and (gff.cd_fundacao = grb.cd_fundacao
    and gff.seq_recebedor = grb.seq_recebedor)
    and grp.id_rub_suplementacao = 'S'
    and gff.dt_referencia = '01/12/2004'
    group by grb.num_matricula, grb.cd_empresa
    The results let me think that exists in some cases diferents cod_entid with the same num_matricula and this is wrong.
    I wanna do a SQL to recoup only the rows that has duplications.
    Is this possible?
    Regards

    You can use the following to find the duplicates:
    select num_matricula matricula, cod_entid, count(*)
    from gb_recebedor_beneficio
    group by num_matricula matricula, cod_entid
    having count(*) > 1
    However, you seem to have a mismatch in your select and group by clauses in your second query. You have grb.cod_entid in your select clause and grb.cd_empresa in your group by clause. That combination will not even run without error, so what you posted must not be what you ran to get the 1430 rows, so you might want to re-check your code carefully.

  • How to select the first row for each pair of values ?

    Hi guys, am hoping someone can help me here.
    If I have 4 tables - Building, Dept, Emp, Text
    B D E T
    A 1 Z blah1
    A 1 X blah2
    A 1 W blah3
    A 2 V blah4
    A 2 G blah5
    A 2 H blah6
    B 1 K blah7
    B 1 L blah8
    B 2 E blah9
    B 2 F blah0
    I need a query that will bring back the first bit of text for each pair of building and dept records.
    So the results I would get would be
    A 1 blah1
    A 2 blah4
    B 1 blah7
    B 2 blah9
    blah2 wouldnt be returned, because we have already had a record from the Building A, dept 1 pairing.
    Likewise we wouldnt get blah5 because we have already had a record from the Building A, dept 2 pairing.
    Can this be done in 1 query??
    Thanks all.
    Message was edited by:
    Scott Hillier

    here you go
    SQL> drop table t;
    Table dropped.
    SQL> create table t(B char(1), D integer, E char(1), T varchar2(5));
    Table created.
    SQL> insert into t values('A', 1, 'Z', 'blah1');
    1 row created.
    SQL> insert into t values('A', 1, 'X', 'blah2');
    1 row created.
    SQL> insert into t values('A', 1, 'W', 'blah3');
    1 row created.
    SQL> insert into t values('A', 2, 'V', 'blah4');
    1 row created.
    SQL> insert into t values('A', 2, 'G', 'blah5');
    1 row created.
    SQL> insert into t values('A', 2, 'H', 'blah6');
    1 row created.
    SQL> insert into t values('B', 1, 'K', 'blah7');
    1 row created.
    SQL> insert into t values('B', 1, 'L', 'blah8');
    1 row created.
    SQL> insert into t values('B', 2, 'E', 'blah9');
    1 row created.
    SQL> insert into t values('B', 2, 'F', 'blah0');
    1 row created.
    SQL> select b,d,t
      2    from (
      3  select row_number() over(partition by b, d order by b,d) rno,b,d,t
      4    from t)
      5   where rno = 1;
    B          D T
    A          1 blah1
    A          2 blah4
    B          1 blah7
    B          2 blah9karthick
    http://karthickarp.blogspot.com/

  • "Pie chart in pivot view  showing only the first column's results" in obiee

    Hi,
    In my pivot view(pie chart view+pivottable),i'm getting only the first column's result in pie chart..
    I have added a column named *'A*' in rows and '*moneyspent*' in measuresfield and the '*period*' in the columnsfield in the pivot view.I'm calculating the sum of
    the rows and columns..
    I'm not getting the sum valueof moneyspent in the pie chart..instead i'm getting only the first column of period in the pivot table in the pie chart.
    can anyone tell how can i get the sum value of pivot table in pie chart?
    Thanks in advance..

    Hi Prash,
    let me try to give you an example based on the paint sample:
    Use Markets.Region, Products.Brand, 'Sales Measures'.Units
    choose a pivot view to display the result: region goes into the rows-section, Brand goes into the columns-section and Units into the measures-section
    In the columns-section add a total using the 'add total' at 'Measure Labels' level
    the result is a total column on the right side of the pivot.
    looking like this:
    Units
    Brands
    Region Enterprise Magicolor Mccloskey Valspar Units Total
    Central 1032.....
    Eastern 1485......
    Southern 824.....
    Western 580
    What I am looking for is a new column 'Units Total pct'.
    If I duplicate the measure to show the values in percent, I'll get a second column per Brand (showing the absolute and percentage values) - that's what I don't want
    Regards
    Andy

  • First row for each entry

    hi
    i have sorted the internal table by field f1 and i need to insert the first row for each f1 entry.
    I tried AT NEW f1. But that doesnt seem to work.
    Kindlly help.
    Thanks.

    *--ENSURE THAT age IS FIRST FIELD IN INTERNAL TABLE it_gir while declaring it.....
    SORT it_gir BY age ASCENDING.
    LOOP AT it_gir INTO wa_gir.
    AT NEW age.
    <b>*--if there are fields which are getting populated with **** instead of original values....then use below statement...</b>
    read table it_gir index sy-tabix.
    MOVE-CORRESPONDING wa_gir TO wa_final1.
    APPEND wa_final1 TO it_final1.
    clear wa_final1.
    ENDAT.
    ENDLOOP.
    now it should definitely work.....
    if not check in debugging mode if data exists or not....!!!
    Regards
    Vasu

  • 64-bit driver only returns first row of table

    I have a C++ application using ADO (the MSADO COM components) and the Oracle OLEDB provider for database access. The application works fine on a 32-bit computer using the 32-bit Oracle client and driver. However, when I run a 64-bit build of the application, running on a 64-bit computer (Windows Server 2008 x64), using the 64-bit Oracle client and driver, a SELECT operation returns only the first row of the table.
    Note that this is only happening with the ActiveX ADO components. ADO.NET is not having a problem.
    In both cases I am connecting to the same database, which is Oracle 10.2 (32-bit) running on a different server. I have tested with Oracle client 10.2.0.4 and 11.1.0.7 and got the same result in both cases.
    I have reproduced the issue with a simple table (one column, NVARCHAR2(255)) and simple code.
    In the code, I execute "select count(*) from tablename" and get the correct record count (more than one record). But when I then open the recordset ("select columnname from tablename"), ADO reports EndOfFile after I have read the first row and called MoveNext on the recordset.
    My Oracle knowledge is limited so I don't know if there are driver properties I should be checking.
    Anyone have ideas?
    Thanks in advance.

    For 10.2 it's fixed in 10204 Patch 21 and higher.
    For 11.1 it's fixed in 11107 Patch 12 and higher.
    Cheers,
    Greg

  • How to return only the first string

    Hi Guys,
    I have a mapping where I am creating a filename from data in within my data file, I am using one of my variables i.e. Account
    The data looks like this
    Account:
    123
    123
    123
    456
    456
    456
    789
    789
    789
    What I want is to is return only the first row u201C123" and concatenate it with a constant to make up the filename.
    Any help will be appreciated.
    Kind Regards,
    CJ Bester

    very simple
    use copy value standard function like below.
    Account------->copyvalue(0)----------->
                                                                      CONCAT------------->TARGET
                                         Constant------->
    Regards,
    Raj

Maybe you are looking for

  • Another Install question

    Hi all, I'm currenty with sky but will be moving back to BT when Infinity is available (shoudbe June) so my questions is, My mater socket is locted in the hallway and i do not hve a electrical socket in the hallway, cn i get BT to move my master sock

  • Using Tomcat security!

    hi.. Just now i'm using application level security thr' server.xml,tomcat-user.xml and each application's web.xml... Now i want to do it for jsps within the application.....So can i? if yes then how....? plz reply.... ..Amita

  • Does Photoshop Elements use the GPU?

    I cannot find a difinitive statement as to whether Photoshop Elements uses the GPU or not. I am about to buy a new computer and I am trying to determine if I should spend the money to get a higher end graphics card or not. The two options in the comp

  • E-mail Issue NEED HELP

    Hello, I have a customer at Santa Clara University who wants to change from a Mac to a PC go figure! He is currently using Apple Mail and wants to export his e-mail addresses to GroupWise (Novell) on the PC. Can you tell me what he would need to do i

  • Visual Composer, Texte Editor, TLINE

    hi, i'm using visual composer to feed a bapi that saves data in a notification. My problem is that when i enter a long text in  VC's text editor, only 132 first carateres are shown in the notification in r/3. Is there any way to break the text entere