Get a specific record in duplicates

Hi Experts,
I have a requirement with source table has duplicates so i need to select a row based upon the a condition.
Source table
EMP_NO ENAME SALARY CODE EMP_ID
1 TOM 1000 1 10
1 JOHN 2000 A 20
1 SAM 3000 A 30
2 TOM 500 1 40
2 SUNG 1500 1 50
Desired Output
EMP_NO ENAME SALARY CODE EMP_ID
1 TOM 1000 1 10
2 SUNG 1500 1 50
I tried with MAX and DENSE_RANK but its not getting me the first row.
Please help. Any help will be highly appreciated.
Thanks,
K

Are you looking for something like this?
(You are free to change the "order by" inside the keep dense_rank statement according to your requirements. But it should be the same order for all columns)
-- Test-Data
with yourtable as
select 1 emp_no, 'TOM' ename, 1000 salary,'1' code, 10 emp_id from dual union all
select 1, 'JOHN', 2000, 'A', 20 from dual union all
select 1, 'SAM', 3000, 'A', 30 from dual union all
select 2, 'TOM', 500, '1', 40 from dual union all
select 2, 'SUNG', 1500, '1', 50 from dual
-- Query:
select emp_no,
       min(ename) keep (dense_rank first order by ename, salary, code, emp_id) ename,
       min(salary) keep (dense_rank first order by ename, salary, code, emp_id) salary,
       min(code) keep (dense_rank first order by ename, salary, code, emp_id) code,
       min(emp_id) keep (dense_rank first order by ename, salary, code, emp_id) emp_id
from yourtable
group by emp_no;

Similar Messages

  • Getting a specific record in table MBEW.

    Where/how can I get the Storage Location (LGORT) for a specific record in table MBEW.
    Regards:
    Phillip Mathopa

    Check MARD Table. The storage location (field LGORT) is linked via check tab T001L to a plant (field WERKS in table T001L)
    The plant is linked via table T001W to a valuation area (field BWKEY in table T001W).
    The valuation area is used as a key field in table MBEW
    By using this link chain you will be able to identiy for a given record in MBEW the accociated storage locations
    Hope this helps
    Martin

  • I need to update specific records(of variable lengths) in a file. I can get the correct record but when I update it(add info), it overwrites part of the record following it. I am using labview 6.0

    I need to update specific records(of variable lengths) in a file. I can get the correct record but when I update it(add or change info), it overwrites part of the record following it. I am using labview 6.0. I need to be able to insert information into the middle of a file without disturbing the data before and after

    It's hard to give more specifics without more detail, but in general you're going to need to read in the entire file, split it into three pieces (everything before the record of interest, the record itself, and everything after the record of interest), modify the record, reassemble the three pieces in proper order, and write the whole thing back to the file.Of course if the file is very large you might not want to actually implement it this way, but conceptually at least, this is what you are looking at.If this file some sort of proprietary format?Mike...PS: this type of issue is why I really like databases...
    Certified Professional Instructor
    Certified LabVIEW Architect
    LabVIEW Champion
    "... after all, He's not a tame lion..."
    Be thinking ahead and mark your dance card for NI Week 2015 now: TS 6139 - Object Oriented First Steps

  • Hierarchical query - How to get all parent records - Duplicate post

    Hi,
    In Oracle, START WITH, CONNECT BY commands will give all the direct and indirect child records. Other way round, is they are command which gives all the parent records till the root? Please let me know. I am working on Oracle 9i Release 2.
    Thanks a lot for your help.
    Edited by: skv on Nov 21, 2008 11:05 AM

    Duplicate post.
    Hierarchical query - How to get all parent records
    Please edit this post heading to duplicate post.
    Regards.
    Satyaki De.

  • The record has duplicate key values - "Include in Unique Index" checkbox missing

    I have a Silverlight client app that I'm developing in Lightswitch in VS2013 Ultimate Update 1, and have run into a problem when adding records.
    I am working against an external SQL Server 2008 database, and the table in question only has the primary key constraint, meaning that the ID field is an identity field, set as the primary key.
    When I try and add records to the table from the app, I get an error "The Shiur record has duplicate key values." This seems to happen when I add a row that has the same Speaker as an existing one. If I add one with a new Speaker then
    it inserts OK.
    Whilst searching for information on this error, I saw many comments around about there being a problem in earlier releases with the "Include in Unique Index" not working properly. This looked like my problem, except for two points...
    1) This table doesn't have anything in a unique index (as far as I know), as I never set it up to have any. You can see the details here...
    This looks to me like there is only the one index, which is the primary key one.
    2) The "Include in Unique Index" checkbox doesn't appear on my Properties panel at all. If I open the table in the designer, then click in the Speaker row, I don't see "Include in Unique Index" at all...
    Actually, I don't see "Include in Unique Index" at all, irrespective of what I click. It's just not there.
    So, I don't seem to have a unqiue constraint to violate, and VS doesn't show me the "Include in Unique Index" to allow me to check this, but I still get the error on insert. Anyone any ideas what's going on here?
    Thanks
    FREE custom controls for Lightswitch! A collection of useful controls for Lightswitch developers.
    Download from the Visual Studio Gallery.
    If you're really bored, you could read about my experiments with .NET and some of Microsoft's newer technologies at
    http://dotnetwhatnot.pixata.co.uk/

    Hi Alan,
    'Include in Unique Index' is for intrinsic database entity properties.
    Ah, that explains why I can't see it then :)
    Is LightSwitch or SQL throwing the error?
    Ah, you're a genius! Well, not quite, but your question led me to the answer.
    For some odd reason, the primary key fields on my tables seem to have lost their identity setting, so when it tried to insert a new record, the ID wasn't automatically increased, so was going in as zero. This worked fine for the first insert, as there wasn't
    a record with zero ID, but failed for the second.
    Changed the ID fields to be identity, and all works fine now :)
    Thanks very much.
    FREE custom controls for Lightswitch! A collection of useful controls for Lightswitch developers.
    Download from the Visual Studio Gallery.
    If you're really bored, you could read about my experiments with .NET and some of Microsoft's newer technologies at
    http://dotnetwhatnot.pixata.co.uk/

  • To Get the earlier records in a table for a particular id neglecting the newer ones

    Hi All,
    I need to get the older records for a particular id rejecting the newer ones..My Scenarios is as follows..
    ID      Result           Date
    1        Pass             2015-01-01
    1        Fail                2015-03-05
    2       Pass                2014-06-07
    2       Fail                  2015-02-02
    My Output will be 
    ID        Result              Date
    1          Pass                2015-01-01
    2          Pass                 2014-06-07
    How can i achieve this....Thanks in advance

    Please follow the basic Netiquette of all SQL forums for the past 35+ years on the Internet. Post DDL that follows ISO-11179 rules for data element names. You have no idea; you do not even know that DATE is a reserved word in SQL! Use industry standard
    encodings (ISBN, UPC, GTIN, etc) and avoid needless dialect. Give clear specifications. Give sample data. Web need to see the keys and constraints, the DRI, etc.  80-95% of the work in SQL is in the DDL. 
    If you do not know that rows are not records, fields are not columns and tables are not files, then you should not be posting. If your tables have no keys, you should not be posting. If you have not tried any DML yourself, you should not be posting. 
    >> I need to get the older records [sic] for a particular product_id, rejecting the newer ones..My Scenarios is as follows.. <<
    Now we have to do all your typing because of your bad manners. Thanks a lot. Here is a repair job. 
    CREATE TABLE Inspections 
    (product_id CHAR(5) NOT NULL,
     inspection_date DATE NOT NULL
    PRIMARY KEY (product_id, inspection_date),
     inspection_result CHAR(4) NOT NULL
     CHECK (inspection_result IN ('pass', 'fail'))
    INSERT INTO Inspections 
    VALUES
    ('prod1', '2015-01-01', 'pass'),
    ('prod1', '2015-03-05', 'fail'),
    ('prod2', '2014-06-07', 'pass')
    ('prod2', '2015-02-02', 'fail'); 
    Here is one way to do this: 
    WITH X(product_id, inspection_date, inspection_result, first_inspection_date)
    AS 
    (SELECT product_id, inspection_date, inspection_result,
            MIN(inspection_date) OVER (PARTITION BY product_id) 
       FROM Inspections)
    SELECT product_id, inspection_date, inspection_result
     FROM X 
    WHERE first_inspection_date = inspection_date;
    --CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
    in Sets / Trees and Hierarchies in SQL

  • Getting duplication of records in the out put of the report on multipro..

    hai ,
          We are trying to execute a report on a multiprovder.While executing the report  we are getting duplication of records while in case if we are removing the created 'new selection' or 'new fromula' in the query designer we are not getting the duplicate records.
    Now as per our requirement we do not need duplicate records.
    Plz could any one help me out with this problem

    Hi Jvr,
    $server | ($_ -split '=')[1] -replace '}' is working.. :)
    The email doesn't have @{ = }, its only displayed in the output.
    Any help on the REGEX part?

  • SQL query to get last 10 records in the table?

    Hi,
    Can anyone tell me the SQL query to get last 10 records in the table?
    Thanks!!
    MCP

    Please, define what "last" means. Sets are unordered by definition, so if you want to retrieve rows from a table in a specific order you need to specify what that order is - e.g. by maintaining a value in a column (or a combination of columns) that you can use in the ORDER BY clause of the SELECT statement.
    If, for instance, you kept the time when the row was inserted in a special column (InsertedTime), you could use this in your query like this:
    select top (10)
      <column list>
      from <table or view>
      where <restriction(s)>
      order by InsertedTime desc;
    ML
    Matija Lah, SQL Server MVP
    http://milambda.blogspot.com

  • Find a specific record in a recordgroup

    I am building a recordgroup at runtime of IDNum and Name. (Basically key-value pairs)
    I'm able to build the recordgroup. But how do I find a specific record to get a Name value if I have an IDNum?
    I know I can just do this with a temp table, but I was trying to do it this way....

    Hello,
    Use the Get_Group_Record_Number() to retrieve the desired row in the record group (see the on-line documentation).
    Francois

  • [php+mysql] how to get the inserted record ID?

    Hi all,
    I have a standard php page that inserts a record in a mysql
    db.
    is there a way to save the record ID on a session variable
    just after
    storing the new record on the db? I would like to be able to
    get this
    record ID on a specific page where I would allow the user to
    print
    this specific record, by filtering the db by this session
    variable.
    I can use MX Kollection (last version, not PRO).
    TIA
    tony

    >...
    >mysql_query(...);
    >$_SESSION['lastId'] = mysql_insert_id();
    >HTH
    >Micha
    Hi Micha,
    I think that it a bit more complicated.
    I can't find any occurrence of that mysql call.
    I used MX Kollection INSERT FORM function.
    here is the code (partially):
    ===============================
    <? // Load the common classes
    require_once('../includes/common/KT_common.php');
    // Load the tNG classes
    require_once('../includes/tng/tNG.inc.php');
    // Make a transaction dispatcher instance
    $tNGs = new tNG_dispatcher("../");
    // Make unified connection variable
    $conn_test_conn = new KT_connection($tes_conn,
    $database_test_conn);
    // Start trigger
    $formValidation = new tNG_FormValidation();
    $tNGs->prepareValidation($formValidation);
    // End trigger
    // Make an insert transaction instance
    $ins_rl_test = new tNG_insert($conn_test_conn);
    $tNGs->addTransaction($ins_rl_test);
    // Register triggers
    $ins_rl_test->registerTrigger("STARTER",
    "Trigger_Default_Starter", 1,
    "POST", "KT_Insert1");
    $ins_rl_test->registerTrigger("BEFORE",
    "Trigger_Default_FormValidation", 10, $formValidation);
    $ins_rl_test->registerTrigger("END",
    "Trigger_Default_Redirect", 99,
    "2.php?idp1={id_rl}");
    // Add columns
    $ins_rl_test->setTable("rl_test");
    $ins_rl_test->addColumn("nome_rl", "STRING_TYPE", "POST",
    "nome_rl");
    $ins_rl_test->addColumn("cognome_rl", "STRING_TYPE",
    "POST",
    "cognome_rl");
    $ins_rl_test->addColumn("datanascita_rl", "DATE_TYPE",
    "POST",
    "datanascita_rl");
    $ins_rl_test->addColumn("cancellato_rl", "STRING_TYPE",
    "POST",
    "cancellato_rl");
    $ins_rl_test->addColumn("cancellato_data_rl", "DATE_TYPE",
    "POST",
    "cancellato_data_rl");
    $ins_rl_test->setPrimaryKey("id_rl", "NUMERIC_TYPE");
    // Execute all the registered transactions
    $tNGs->executeTransactions();
    // Get the transaction recordset
    $rsrl_test = $tNGs->getRecordset("rl_test");
    $row_rsrl_test = mysql_fetch_assoc($rsrl_test);
    $totalRows_rsrl_test = mysql_num_rows($rsrl_test);
    ?>
    ===========================
    as you can see, all data is processed by other functions in
    other
    included files.... :(.
    I think I need to better understand the TNG engine and try to
    create a
    little trigger that creates a session variable just after
    inserting
    the record in the db.
    I already tried to do so, honestly, but with really poor
    results.
    Ciao Micha. ;).
    tony

  • Move To A Specific Record

    http://63.134.247.210/searches/doubles.asp
    DW 8.02 Win XP Pro
    How do I get the "Move to specific record" object to work on
    this .ASP
    page? I have been trying for days and can not even get it to
    show up on the
    page.
    Thanks,
    Bobby

    How about something along the lines of this ?
    Ps. you might want to use Scrollable resultsets if you want to move back up the
    resultset.
    regards,
    Owen
    boolean found = false;
    while ( (!found) && (resultset.next()) )
        int id = resultSet.getInt ( "id");
        if (id == 1979 )
           found = true;
    if (found)
        // we're positioned on the right record
    else
       // throw exception... couldn't find the id
    }

  • How to display/navigate to specific record in a table with more then thousand records

    Hi,
    there is a task that I do not know how can be resolved.
    There is a query that returns around 1 - 2 thousand records. And all those records have corresponding weight assigned.
    After query executing it is necessary to navigate to the records with the highest weight assigned. It can be first record, it can be a record at the end or in the middle of the row set from thousand records.
    I have used "DisplayRow"=selected or the code below, but it does not work properly ... when the record that we navigate is in the middle of record set from 2000 records, then users have to scroll down to it.
    And I need to position to that specific record after query is executed.
    So I used the code below:
    public void onButtonClicked(ActionEvent actionEvent) {
    DCBindingContainer bc = (DCBindingContainer)BindingContext.getCurrent().getCurrentBindingsEntry();
    DCIteratorBinding iterator = bc.findIteratorBinding("ViewVIIterator");
            Row row = iterator.getCurrentRow();
            String bestPosition = (String)row.getAttribute("BestPosition");
            iterator = bc.findIteratorBinding("DetaillVIIterator");
            ViewObject vo = iterator.getViewObject();
            vo.setWhereClause(some_conditions);
            vo.executeQuery();
            RowSetIterator rowSet = iterator.getRowSetIterator();
            Key key = null;
            while (rowSet.hasNext()) {
                row = rowSet.next();
                if (row != null && ((String)row.getAttribute("weight")).equals(bestPosition)) {
                    key = row.getKey();
                    Key rowKey = row.getKey();
                    ArrayList tableRowKey = new ArrayList();
                    tableRowKey.add(rowKey);
                    this.getRangeTable().setScrollTopRowKey(tableRowKey);
                    break;
    After the code above I getting the row selected or set as a current, but in case of 2000 records, when my record is in the middle of this record set, I need to scroll down to this record to see it.
    And I wanted that I will be navigated to my record with records above and below.
    What am I doing wrong above?
    Thanks
    Alexander

    Hi Timo!
    thanks for the reply.
    version info:
    Oracle JDeveloper 11g Release 2 11.1.2.3.0
    Studio Edition Version 11.1.2.3.0
    Build JDEVADF_11.1.2.3.0_GENERIC_120914.0223.6276.1
    IDE Version: 11.1.2.3.39.62.76.1
    Product Version: 11.1.2.3.39.62.76.1
    1. sorting order is already applied and we to position to a specific record in af:table.
    From another side the task can rephrased: I need to position to a specific record and I need to be able to show 500 records before and 500 records after.
    So where clause can be like:
    :bestPosition > position - 500 and :bestPosition < position +500.
    2. I tried to apply your second approach and found that record is selected, but I need to scroll to it down. It happens when first 20 records are displayed in af:table and my record is 480 records below ...
    Alexander

  • How to get customer-specific objects into PCUI ?

    Hello,
    we want to get an Z-table as tab page of the business partner-application into PCUI. It should 'only' be possible to create new entries - today there is no need to modify or delete records.
    Does there exist something like a "cookbook" on this task or has anyone of you experience how to get customer-specific objects (without using EEWB) into PCUI ?
    Thanks in advance
    Martin

    Option 1:
    If you are good in ABAP.
    You can add new tab in which create a new Field group. Assign it to a model access clas in which handle the table update.You can get the details in PCUI cookbook itsel.
    Option 2:
    If you are good at java
    Develop an FM to update the table.
    Call the FM from webdynpro
    Include this webdynpro as HTML viewer in PCUI.
    Regards,
    Abdul Raheem S

  • How to get the last record from the database

    I am using MS Access database and Swings as GUI. I want to get the last record of a particular column from the table and store it as a varaible.

    Hi
    To get Last record of resultset, you have pass some parameter in constructor of CreateStatement.In such case Resultset should be scrollable and Readonly
    Example
    objStatement=objCon.createStatement ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
    mwwResultSet=cwwStatement.executeQuery(mwwSqlQuery);
    while(mwwResultSet.next())
    if(mwwResultSet.isLast())
    //Fetch the required column record.
    String abc=mwwResultSet.getString(1);
    I think this will work. Try it.
    bye

  • How to get the last record of an internall table ....

    Hi All..
    i want to get the last record of an internal table itab, and i want the the value of the last record.

    Hi,
         Use describe statment.
    data: lv_line type i.
        Describe table itab lines lv_line.
        read table itab into wa_itab index lv_line.
    regards,
    Santosh Thorat

Maybe you are looking for

  • How can i display page number in this format in xml publisher report (1-1)

    in this format 1-1 1-2 1-3 2-1 2-2 2-3 can i display page nos in this format in xml publisher please help me on this

  • Order Process Sequence Problem

    Currently I have a FM that does data from an incoming PO IDoc, makes some conversions, changes, etc.  It saves these changes into a new IDoc structure and then uses IDOC_INBOUND_ASYNCHRONOUS FM to post them to create orders.  The problem is if I have

  • Downgrading Minutes Plan adding Unlimited texting

    OK, I feel like an idiot trying to make a change to less minutes (From 1400 to 700) but unlimited texting.  I currently have the family plan with 3 additional lines.  I ran the analysis it said we only were using about 200 minutes per month, but goin

  • JCA Resource Adapter Deployment in OAS 10.1.2

    Hi, I have installed the Oracle Application Server 10g Release 2 (10.1.2) (j2ee & web cache) and I want to know how I can deploy a JCA Resource Adapter. Until now I have work with Oracle Application Server 10g Release 3 (10.1.3.1.0) and this version

  • How to debug UIX pages?

    Hi, I was reading the "Configuration" file uix-config.xml, but i can't debug a UIX page... It's possible to debug uix pages? Thanks Juan Pablo