How to retrieve unique records with multiple columns

I have a sps_prod table as described below-

POGNAME VARCHAR2 (1500)
INDEX #VERSION VARCHAR2 (200)
POG_MODEL_STATUS VARCHAR2 (100)
POG_LAYOUT_TYPE VARCHAR2 (500)
POG_MARKET_SPECIFIC VARCHAR2 (500)
POG_CONTACT_NUMBER VARCHAR2 (100)
AREA_SUPPORTED VARCHAR2 (500)
POG_COMMENTS VARCHAR2 (1500)
POG_FOOTER_COMMENTS VARCHAR2 (1500)
POG_ELECTRICAL_LIST_1 VARCHAR2 (1500)
POG_ELECTRICAL_LIST_2 VARCHAR2 (1500)
POG_CARPENTRY_1 VARCHAR2 (1500)
POG_CARPENTRY_2 VARCHAR2 (1500)
INSTALLATION_INSTRUCTION_1 VARCHAR2 (1500)
INSTALLATION_INSTRUCTION_2 VARCHAR2 (1500)
FIXTURE_REORDER_NUMBER VARCHAR2 (200)
FIXTURE_ID VARCHAR2 (200)
FIXTURE_NAME VARCHAR2 (500)
FIXTURE_IMAGE VARCHAR2 (500)
PART_REORDER_NUMBER_9 VARCHAR2 (500)
PART_FIXTURE_ID_9 VARCHAR2 (500)
PART_FIXTURE_NAME_9 VARCHAR2 (500)
PART_FIXTURE_IMAGE_9 VARCHAR2 (500)
UPC VARCHAR2 (50)
ITEM_NUMBER VARCHAR2 (50)
DESCRIPTION VARCHAR2 (700)
MERCH_TYPE VARCHAR2 (20)
HEIGHT VARCHAR2 (100)
WIDTH VARCHAR2 (100)
DEPTH VARCHAR2 (100)
DATE OF CREATE_TS

There are 4 million records in it and many with the same combination of POGName, #Version, POG_Model_Status, POG_Layout_Type, POG_Market_Specific, POG_Contact_Number and Fixture_Name Index. How do the records to retrieve all the columns above, but with a unique combination of fixture_name and reorder_number. It has no keys defined on the table.

I guess that it is a simple problem but the fact I'm trying to retrieve all the columns I'm stumbling.

Thanks in advance.

Hello

Sanders_2503 wrote:
... There are 4 million records in it and many with the same combination of POGName, #Version, POG_Model_Status, POG_Layout_Type, POG_Market_Specific, POG_Contact_Number and Fixture_Name Index. How do the records to retrieve all the columns above, but with a unique combination of fixture_name and reorder_number.

I don't see a column named reorder_number. Do you mean fixture_reorder_number or part_reorder_number_9?

So, you want only one row for each distinct combination of fixture_name and some other column (I'll assume it's fixture_reorder_number). Does it matter which line? They will not necessarily have the same values for the other columns.
The following query returns the one with the first pogname (in sort order):

WITH     got_r_num     AS
(
     SELECT  pogname, index#version, pog_model_status, pog_layout_type
     ,     pog_market_specific, pog_contact_number, fixture_name
     ,     ROW_NUMBER () OVER ( PARTITION BY  fixture_name
                               ,                    fixture_reorder_number
                         ORDER BY        pogname
                       )         AS r_num
     FROM    sps_prod
)
SELECT  pogname, index#version, pog_model_status, pog_layout_type
,     pog_market_specific, pog_contact_number, fixture_name
FROM     got_r_num
WHERE     r_num     = 1
;

If there be a tie (i.e. two or more lines with the same fixture_name, fixture_number and pogname first) and then the will be chosen arbitrarily.

Instead of "ORDER BY pogname", you can ORDER all the other columns OR expressions, but you must have an ORDER byclause of analytics. You can do "ORDER BY NULL" If you really want pcik an arbitrary line.

I hope that answers your question.
If not, post a small example data (CREATE TABLE and only relevant columns, INSERT statements), and also publish the results you want from these data (or some examples of acceptable results).
Explain, using specific examples, how you get these results from these data.
Always tell what version of Oracle you are using.

Tags: Database

Similar Questions

  • retriving of unique records on two columns

    Hello world


    Using sql query, that he must retrieve unique records on two columns.

    Example of table source: raster columns [uwi, well_no]

    Examples of data below


    UWI well_no

    -----    --------

    1 988311

    1 988311

    1 1032662

    1 1032662

    2 103

    2 103

    2 103

    3

    3 104

    3 104

    3 104

    4 106

    4 107

    4

    4 108

    For a given

    UWI: 1 there are 4 well_no which is having two distinct values where these documents I need to go get

    UWI: 2 there are 3 well_no, all 3 well_no contains the same value as (103) Consequently, these documents should not seek

    UWI: 3 there are 4 well_no (1 null and 3 values are the same (104)] where these records should not seek.)

    UWI: 4 there are 4 well_no which is to have three separate with a single value zero so these 4 files, I need to get.

    output:

    UWI well_no

    -----    --------

    1 988311

    1 988311

    1 1032662

    1 1032662

    4 106

    4 107

    4

    4 108

    Thank you

    Jery

    Hi, Michel,.

    Whenever you have a question, please post CREATE TABLE and INSERT statements for your sample data, so people who want to help you can recreate the problem and test their ideas.

    Format your message so that it is easy to read and understand.

    Always say what version of Oracle you are using (for example, 11.2.0.2.0).

    See the FAQ forum: https://forums.oracle.com/message/9362002

    Maybe you want something like this, which shows information about the jobs that have deptnos 2 or more not NULL:

    WITH got_cnt AS

    (

    SOME jobs, deptno

    , ACCOUNT (SEPARATE deptno) RESUMED (work PARTITION) AS cnt

    FROM scott.emp

    )

    SOME jobs, deptno

    OF got_cnt

    WHERE cnt > 1

    ;

  • LOBs and how to retrieve the record inserted with EMPTY_BLOb()

    Hi guys


    How to retrieve the records inserted with EMPTY_BLOb() instead of NULL value.


    Best greetings
    A.G.

    There must be a better way, but these work:

    SELECT... from tableX where length (lob_column) = 0;
    SELECT... from tableX where dbms_lob.getlength (lob_column) = 0;

    Concerning
    Jonathan Lewis
    http://jonathanlewis.WordPress.com
    http://www.jlcomp.demon.co.UK

    "All experts it is a equal and opposite expert."
    Clarke

  • How to configure a VM with multiple network cards to see Agent?

    How to configure a VM with multiple network cards to see Agent?

    We can archive this requirement by configuring the subnet used view Agent.

    The subnet determines which view address of Network Agent provides the server instance to connect to view for the client protocol connections. The view on VM officer has more than one NIC

    Follow the procedure below:

    on a display Agent installed VM,

    * Recording of VM session.

    * RUN--> type regedit or type regedit.exe at the command prompt

    * Create a registry entry to configure the subnet.

    For example: is HKLM\Software\VMware, Inc. \VMware VDM\Node Manager\subnet = n.n.n.n/m type - REG_SZ.

    In this example, n.n.n.n is the TCP/IP subnet, and m is the number of bits in the subnet mask.

  • Unique table with several columns or several tables split?

    What is the best.

    A table with multiple columns inside or divided into several tables. Why?
    How will the performance in the two scenarios?

    Hello

    user13024762 wrote:
    I have a table EMP that has column EMP_ID, EMP_NAME MGR_ID, MGR_NAME, SALARY, EXP_IN_MNTHS, EXP_IN_YRS... etc with multiple columns

    I have the following tables
    EMP-> EMP_ID, EMP_NAME

    Each row in the table emp thie represents a separate employee. I guess other columns in the emp table might be birth_date, social_security_number and status (by example, 'Active', 'Leave', 'complete'). Here's what an employee has (at least) one of. If there is a one-to-many relationship between an employee and an attribute, then you probably want another table for this attribute.

    BISHOP-> EMP_ID, MGR_ID, MGR_NAME

    There is a one-to-many relationship between employees and managers? In other words, an employee may have 2 or more managers? If Yes, then you need another table.
    If there is only a one-to-one relationship between employees and managers (in other words, if an employee is never more than 1 Manager) so why don't you just have a mgr_id column in the emp table?
    Managers are also used for? (This is often the case, as in scott.emp and hr.employees.) If so, do not store their names in the EME and tables of mgr. Store name (and date of birth and other information) in the table emp only and, if you need a table of Bishop, just the emp_id and mgr_id column.

    SAL-> EMP_ID, SALARY

    There is a one-to-many relationship between the employees and wages? In other words, an employee may have 2 or more treatments? If so, how will you use the values? Is a special treatments in some way, as it will be used more often than others? (In other words, you may have a current and past wages salary, but the last wages are rarely used.)
    If you never have more than 1 salary for a given employee, why not just have a sal column in the emp table?

    EXP-> EMP_ID, EXP_IN_MNTHS, EXP_IN_YRS

    There is a one-to-many relationship between the employees and what whether you store in this table?

    etc. with more tables

    What is the best based on

    (1) performance and data recovery
    (2) ease of use
    (3) maintainability

    A one-to-many relationship requires an additional table. If an employee can have up to 3 managers, don't have mgr1, mgr2 and mgr3 columns in the emp table. Use a separate table, with up to 3 lines for the same employee, instead.
    For 1-1 relationships, it is usually best to not have separate tables.

  • Gears - error when you try to insert values into a table with multiple columns

    Hello

    I started playing with the gears and SQlLite today and I get an error when I try to insert values into a table with multiple columns.

    I have:

    var db = google.gears.factory.create('beta.database');
        db.open('developerSet');
        db.execute('create table if not exists Developers (DeveloperName text, DeveloperAge int)');
    
        var devName = "Davy"
        var devAge = 32;
    
        try {
            db.execute('insert into Developers values (?, ?)', [devName, devAge]);
            alert('success');
        }
        catch (e) {
            alert(e);
        }
    

    I get the error:

    net.rim.device.api.database.DatabaseException; insert into developers values (?,?): SQL logic error or missing database.

    I use this reference: http://code.google.com/apis/gears/api_database.html

    Everything works if I have only one field as:

    var db = google.gears.factory.create('beta.database');
        db.open('developerSet');
        db.execute('create table if not exists Developers (DeveloperName text)');
    
        var devName = "Davy"
        var devAge = 32;
    
        try {
            db.execute('insert into Developers values (?)', [devName]);
            alert('success');
        }
        catch (e) {
            alert(e);
        }
    

    I use the plug-in Visual Studio 2.0 for 2008 that are running Windows XP SP and Simulator 2.13.0.56

    Thank you

    Davy

    Yes, a SQLite database will persist between battery pulls.  The database is registered either to internal MEM or removable media (not the device memory), depending on which is available on your device.

    In general, its not considered a best practice to remove your table as soon as it is empty and re - create it again when you want to add data.  This adds extra overhead fresh for the final, delete and insert first for a given table.  Instead, define and finalize your drawing before you create your table.  Once created, review the static schema.

    That being said, for development purposes, it may be easier to provide an easy way to drop your tables while you develop your schema.

    See you soon,.

    Adam

  • GROUP BY with multiple columns.

    I have a little query on the GROUP BY clause.

    Sometimes, we will give several names of columns in GROUP BY. If it behaves in the same way as ORDER BY (multi-column) I wish I had an example where I can use GROUP BY multiple columns. in any case regardless of his behaviour, it will be really appreciated if someone can explain a scenario where GROUP BY with multiple columns can be used.

    I know about the use of GROUP BY aggregate functions, but using a single column.

    Thank you.. !!!

    No, not like that

    I think that Group by does not follow any order...

    If we execute like this

    SELECT registrationid, dateofbirth, sum (age) FROM prawin62 WHERE registrationid = 22 GROUP BY dateofbirth, registrationid.

    22     1/23/1975     54
    22     5/18/2011     330
    

    It will give the same result based on date of birth...

    ~ Praveen

  • Call a select stmt with multiple columns inside another column

    Hi all

    I have a question about the appeal of a select statement, which is to have multiple columns inside another select statement.

    I know that we can use inline views to retrieve data from another table within a query as shown below.

    SELECT (SELECT dname FROM dept WHERE deptno = e.deptno), deptno, sal FROM emp e;

    Now, I'm going to pull the loc also column within the same view of inline. But oracle is not allowing me to do the same thing.

    Is there a way we can achieve the same thing because I don't want to hit the area two times table each time for each emp record.

    Appreciate your valuable suggestions.

    Thank you
    Madhu K.

    Maybe just a simple outer join?

    select ut.subscriberid
          ,ut.unitid
          ,ut.install_date
          ,nvl(tuh.hardwaretype, 'NO_HW')
    from   tt_unit ut
    left   join tt_unit_hwtype tuh
    on     tuh.unitid = ut.unitid
    where  trunc(ut.install_date) >= V_CONST_PROG_START_DT;
    
  • How to get the record with a tank of extra space

    Hi I have a value which have several entries with the same value but some record have more space, how to know which record


    Ex:


    'abc1234 '.

    'abc1234 '.

    'abc1234 '.


    I want to know 'abc1234' record


    in this table, I have more than 50 million records.

    Maybe this:

    SELECT s FROM T WHERE s LIKE '% '.

  • Declare a type of table with multiple columns

    I have a table with a column of type, and I want to create one with two columns.

    My type is:
    create or replace type "NUMBER_TABLE" in the table of the number;

    And I use it in function:

    FUNCTION GetValues()
    return NUMBER_TABLE
    as
    results NUMBER_TABLE: = NUMBER_TABLE();
    Start
    Select OrderId bulk collect in: results from (select * from tbl_orders);
    -Other code...
    end;

    I want select it be like this:
    Select OrderId, OrderAddress bulk collect into: results from (select * from tbl_orders);

    How to do this?

    Is that what you are looking for:

    CREATE OR REPLACE TYPE two_col_rec AS OBJECT (empno NUMBER, ename VARCHAR2(10))
    /
    
    CREATE OR REPLACE TYPE two_col_table AS TABLE OF two_col;
    /
    
    CREATE OR REPLACE FUNCTION GetValues RETURN two_col_table AS
       results two_col_table := two_col_table();
    BEGIN
       SELECT two_col(empno, ename) BULK COLLECT INTO results FROM emp;
       --
       RETURN results;
    END;
    /
    show errors
    
  • How to create a table with editable column values.

    Hello world
    I think it's very simple, but I am unable to find how to do this. This is my requirement. I need to create a table with n columns and 1 line initially. the user must be able to enter data into this table and click of a button must insert the data into the database table. Also, there should be a button at the bottom of the table to add 1 line to the table.

    I know how to do the insertion of data, but can someone please let me know how to create a table which allows the user to enter data and how to create a line button Add 1?


    Thanks in advance!

    Raghu,

    Go through the tutorial of Toolbox Page & Advanced section of the Guide of the OFA table.

    Step 1 - you need to create EO & VO from this EO. This EO will be table of database where you want to insert the data.

    Step 2 - create an advanced table region. (See this section in table advanced for more details)

    Step 3 - attach this VO in the BC4J region advanced Table component.

    Kind regards
    GYAN

  • How long can I record with the soundrecorder?

    I need to record some interviews which will have more than one hour each. The easiest way for me would be to take my laptop and write it down. My question: if I use the normal soundrecorder, how long can I record? Is it possible to save over an hour? Thank you!

    I would expect that you could take an occasional break in such
    a long interview... to create several files might not be a bad
    idea... but I think it will continue to record until you use
    all your free space.

    The following article can offer a few ideas:

    Windows Vista sound recorder
    http://www.JakeLudington.com/windows_vista/20060524_windows_vista_sound_recorder.html

  • AVCHD - how to retrieve and record separate clips?

    My first go with AVCHD, which I don't know anything about except that after having bought a beautiful new Sony video camera I did on my first try, a single file called AVCHD, even though I've taken several separate clips. When I click on this file on my computer, it opens and displays thumbnails of each of the separate clips. When I click on one of the clips that it opens in QuickTime and here I can export the file to save it as a separate sequence on my computer.

    Is there an easier way to batch save clips separated or do I need to go through this process of opening each separately in QuickTime and exporting to save him?

    Any information on how I should approach work with this AVCHD format would be also greatly appreciated.

    TIA,

    Ken

    Ok.

    Mac OS recently mucked this upward.  He no longer sees the correctly as a bunch of files in the form of files (like any good manager should), it seems more like a package of QuickTime.  There are "open package" as it was to get the files inside.

  • HOW TO SET UP RECORDING WITH ADOBE CS5 IN WINDOWS7

    Hi all. I used to record with hearing and then make my own MP3 W XP compulations.

    Now, I have 7 W and new Audition CS5 and of course, can not save. When I press the record button, message here is that appears:

    the sampling rate of the output devices and audio do not match. audio cannot be recorded unti it's fixed.

    Use the control panel operating system or device appropriate to adjust the frequency of sampling of input and output devices to use the same settings.

    Also, just in case where, what else do I need to do in Windows 7 to allow the recording of the hearing of Winamp or any other music source?

    I looked at my audio devices in the Control Panel, I have S/PDIF sound card integrated into the motherboard.

    Thank you

    I think that what you describe is normal operation of the console reading in Windows 7, except that it is only sometimes the faders move together, rather than always.

    I also think that Emmrecs is right. Go Win7 Panel and select the "Recording" tab, then right-click on an empty space on the tab. You should look for what is called "Stereo Mix" or "what you hear".

    If you see that a listed Microphone and no option to activate disconnected or disabled devices, you will need to go get a third-party tool.

    As I say, I use Total Recorder. It has been around for years and works the way you want with earlier versions of the hearing. There are other applications that use others.

    All your problems are with Windows 7, I'm afraid.

  • ComboBox with multiple columns

    Is it possible to make a ComboBox with two columns in the drop-down list box?

    Thank you

    Use the dropdownwidth property

Maybe you are looking for