Distinct record help!

Hi All,
Hope you are doing great!
I have the following query.
SELECT DISTINCT DT.STD_ID STDID,
UP.FIRST_NAME FIRSTNAME,
UP.LAST_NAME LASTNAME,
DT.TYPE ROLE,
NVL2 (CT.USER_ID, 'Y', 'N') CKCTEAM,
CT.USER_ID
FROM DEAL D,
DEAL_TEAM DT,
CKC_TEAM CT,
USER_PROFILE UP
WHERE D.DEAL_ID = DT.DEAL_ID
AND DT.STD_ID = UP.STD_ID
AND D.DEAL_ID = 'D0002064';
And the following result.
STDID     FIRSTNAME LASTNAME ROLE     CKCTEAM     USER_ID
V285773     MAHIA     ANNA     CREATEBY     Y     E067448
E015989     JACQU     CARR     EDITOR     Y     E067448
V285773     MAHIA     ANNA     BANKER     Y     E067448
O256285     ALLA     OLWEN     EDITOR     Y     E067448
I need the results to have distinct records based on the first name and last name irrespective of the roles. Now you can see from the result set that there is a duplicate record for "MAHIA     ANNA" since the user has 2 different roles.
Appreciate your help on this.
Thanks in advance
MN

Use query from my previous post, if you want to group your records only by names. Or this, if you want to group by all except role.
SELECT DT.STD_ID STDID,
UP.FIRST_NAME FIRSTNAME,
UP.LAST_NAME LASTNAME,
max(DT.TYPE) ROLE,
NVL2 (CT.USER_ID, 'Y', 'N') CKCTEAM,
CT.USER_ID
FROM DEAL D,
DEAL_TEAM DT,
CKC_TEAM CT,
USER_PROFILE UP
WHERE D.DEAL_ID = DT.DEAL_ID
AND DT.STD_ID = UP.STD_ID
AND D.DEAL_ID = 'D0002064' group by DT.STD_ID,UP.FIRST_NAME, UP.LAST_NAME,CT.USER_ID;

Similar Messages

  • Select distinct records in Mapping with no Key field (all fields can vary)

    Hi Experts,
    Let me take an example (not the actual requirement but same scenario) to explain the problem where I need your help to get best possible way to resolve. This has to be achieved in mapping, don't have other options as its part of complex end 2 end scenario.
    I have following input XML:
    <Employee>
       <Details>
          <Id>123</Id>
          <Name>ABC</Name>
         <Role>Manager</Role>
          <Area>Bangalore</Area>
        </Details>
        <Details>
           <Id>123</Id>
           <Name>ABC</Name>
            <Role>Manager</Role>
             <Area>Pune</Area>
         </Details>
          <Details>
           <Id>123</Id>
           <Name>ABC</Name>
            <Role>Advisor</Role>
             <Area>Bangalore</Area>
         </Details>
          <Details>
           <Id>123</Id>
           <Name>ABC</Name>
            <Role>Manager</Role>
             <Area>Bangalore</Area>
           <Details>
           <Id>143</Id>
           <Name>ABC</Name>
            <Role>Manager</Role>
             <Area>Bangalore</Area>
         </Details>
    </Employee>
    The output XML is:
    <Employee>
       <MainRec>
           <Id>123</Id>
            <Name>ABC</Name>
             <table name = 'Roles'>
                   <record>
                          <Id>123</Id>
                           <Role>Manager</Role>
                            <Area>Bangalore</Area>
                      </record>
                      <record>
                          <Id>123</Id>
                           <Role>Manager</Role>
                            <Area>Pune</Area>
                      </record>
                      <record>
                          <Id>123</Id>
                           <Role>Advisor</Role>
                            <Area>Bangalore</Area>
                      </record>
                  </table>
          </MainRec>
          <MainRec>
            <Id>123</Id>
            <Name>ABC</Name>
             <table name = 'Roles'>
                   <record>
                          <Id>143</Id>
                           <Role>Manager</Role>
                            <Area>Bangalore</Area>
                      </record>
                </table>
            </MainRec>
    </Employee>
    As you can see from the example above, here I want to populate only distinct records under table, but there is no key fiield to ditunguish. Any of the 3 fields (Id, Role,Area) can vary and between 2 records if all of these fields are same then its duplicate else select it. So in above XML just discard the 4th record from the source XML and populate all others. Each record has to be checked against all other records all 3 values (ID, Role, Area). Only when none of the records have exactly the same values, populate it.
    Also records with different ID come under different table node. Hope my requirement is clear, if not please let me know, i will try to explain better.
    I thought of creating a UDF to achieve this but not able to decide how to match it to the output message here.
    Best Regards,
    Pratik

    Hi,
    For the main record, I think you only need to check for each unique ID, e.g
    Id --> removeContext --> sort:ascending --> splitByValue:valueChanged --> collapseContext --> MainRec
    For the record, however, you need to create a UDF that will filter out the duplicate values. For this, the UDF sample mentioned here contained multipleResult lists
    Id --> removeContext --> concat: : --> concat: : --> UDF --> splitByValue:ValueChanged --> record
    role --> removeContext --> /          /                \ --> Id
    area --> removContext -------------> /                  \ --> role
                                                             \ --> area
    Context type UDF
    Arguments: input
    Result: IdResult
    Result: roleResult
    Result: areaResult
    Vector temp = new Vector();
    for(int a=0;a<input.length;a++){
       if(!temp.contains(input[a])
             temp.add(input[a]);
    for(int a=0;a<temp.size();a++){
       String tmp = (String) temp.get(a);
       /*split according to field */
       IdResult.addValue(tmp.substring(0,tmp.indexOf(":")));
       roleResult.addValue(tmp.substring(tmp.indexOf(":")+1,tmp.lastIndexOf(":")));
       areaResult.addValue(tmp.substring(tmp.lastIndexOf(":")+1,tmp.length()));
    note: Id and record will both be using the IdResult list.
    Hope this helps,
    Mark

  • How to distinct records?

    hi,
    i need to distinct records in my query but i don't know how to do that.
    i use SQLX functions. this is my query:
    select xmlelement ("narqdi",
    xmlelement ("order",
    (select xmlagg (
    xmlconcat (
    xmlelement ("nom_order", nor.nom_order),
    xmlelement ("nch", nor.chnom1),
    xmlelement ("partida",
    (select xmlagg (
    xmlconcat (
    xmlelement ("npartida", nor2.npartida),
    xmlelement ("ppnom",
    (select xmlagg (xmlelement ("pnom", nor3.pnom))
    from narqd_order nor3
    where nor3.nom_order = nor2.nom_order
    and nor3.npartida = nor2.npartida
    from narqd_order nor2
    where nor2.nom_order = nor.nom_order
    from narqd_order nor
    where nor.NOM_ORDER = '5970'
    from dual
    i have 18 records in table for record nom_order = '5970' and i receive 18 tags <partida> and 18 tags for each ppnom :(
    please help me.
    i tried to put distinct in every select but this is no reason.
    i tried to put agregate function in each select statement but in select for <pnom> it does not work...
    best regards
    Message was edited by:
    Fitibaldi
    Message was edited by:
    Fitibaldi

    Arti,
    Here's another solution (that will still use locking, and can help avoid the "lost update" problem):
    http://stegemanoracle.blogspot.com/2006/03/using-updatable-views-with-adf.html
    John

  • "Select Distinct Records" Option Not Available

    Hello Experts.
    I am working on a new report in CR XI, and noticed that I had many duplicate records.  I went to the File; Report Options; and expected to click on "Select Distinct Records", but that choice was grayed-out.  What would have caused me to lose this option, and how do I fix it?
    Thanks in advance for your help.

    Not sure if this covers it or not, but....
    The Select Distinct Records command is only available for ODBC, OLE DB, and SQL native drivers; it is not available for Stored Procedures. Note also that your server may automatically sort returned values if no sort is specified in Crystal Reports.

  • Distinct records with conditional select formula

    Post Author: nelsonchris
    CA Forum: Data Connectivity and SQL
    Hello,
    I have a simple report pulling data from two tables. I want
    only distinct records. I am selecting records based on
    parameters; here is the select formula:
    ({?Service Name} = "*" or {selsvc.ServiceName} like
    {?Service Name})and
    ({?Program Name} = "*" or {selsvc.Selected Service Entry 
    Program Name} like {?Program Name}) and
    ({?Agency Name}  = "*" or {selsvc.Selected Service Entry 
    Agency Name} like {?Agency Name})
    The problem comes from the fact that Crystal will add the
    selsvc fields to the reports SQL select code, which has the
    effect of duplicating some records that do not have the same
    values for the selsvc fields. The select formula above is
    the only place in the report where values from the selsvc
    field are used, and as you can see they are only used when
    the user has submitted a matching parameter for them. I can
    not figure out how to get rid of the duplicates, please
    help!
    Thanks for your time,
    Chris

    Post Author: yangster
    CA Forum: Data Connectivity and SQL
    I don't follow why you are getting duplicates with your selectionare you getting duplicates without the selection criteria?if you are then they really are not duplicates and there could be issues with your joins between the 2 tables

  • How  to divide distinct records in a table into batches

    Hi all,
    I need a small help . I have some 3 to 4 lakhs of records in table . I want to divide these records into batches by assigning some batchno to some set of records. i.e i'll query some distinct records those distinct records should be assigned to one batchno . i.e when i query there may be some 100 records of one unique value in a column and 1000 next and so on . I want to make these records to one one batchno . Can any one help in this regard.
    Regards,
    rakesh

    May below given SQL help you...
    WITH T AS
    SELECT 'A' COL1 FROM DUAL UNION ALL
    SELECT 'B' COL1 FROM DUAL UNION ALL
    SELECT 'D' COL1 FROM DUAL UNION ALL
    SELECT 'A' COL1 FROM DUAL UNION ALL
    SELECT 'X' COL1 FROM DUAL UNION ALL
    SELECT 'P' COL1 FROM DUAL UNION ALL
    SELECT 'B' COL1 FROM DUAL
    SELECT COL1 , 'BTCH_'||DENSE_RANK() OVER (ORDER BY COL1) BATCH_NO
    FROM   T;
    COL1     BATCH_NO
    A     BTCH_1
    A     BTCH_1
    B     BTCH_2
    B     BTCH_2
    D     BTCH_3
    P     BTCH_4
    X     BTCH_5
    7 rows returned in 0.00 seconds     *009*

  • Convert comma delimed values to distinct records

    Hello,
    i wrote the following code to get the data from comma delimited row into distinct values to another table. say for example my data into column looks like this.
    long_string column data looks like this:
    11,12,14,16,13,18,17
    11,12,13,15,16,17,18,19,20,30
    11,20,30,40,67,90,87,65,76,43,23,56,78,90,12,22,34 - which doesn't have a comma at the end of the data.
    i need to convert this into distinct record for each rows data.
    i used mod function...
    can some one help me.
    DECLARE
    cursor c_1 is select LONG_STRING from TEST;
    rec c_1%rowtype;
    temp_VAR varchar2(100);
    size_of_VAR number;
    number_of_VAR number;
    i number;
    cur_VAR varchar2(3);
    begin
    open c_1;
    loop
    fetch c_1 into rec;
    exit when c_1%notfound;
    temp_VAR := rec.LONG_STRING;
    size_of_VAR := length(temp_VAR);
    number_of_VAR := size_of_VAR/4;
    if (mod (size_of_VAR,4) = 0) then
    for i in 1..number_of_VAR loop
    cur_VAR:=substr(temp_VAR,1,3);
    INSERT INTO TEST_ST (LONG_ST_NUM)
    VALUES ( cur_VAR);
    temp_VAR:= substr(temp_VAR,5);
    end loop;
    else
    dbms_output.put_line('Rules problem for LONG_STRING: ' || rec.LONG_STRING);
    end if;
    end loop;
    close c_1;
    end;
    Thanks...

    Ah, I see, I took my requirement from the later posters as it wasn't clear from OP. It's not the aggregation problem that Listagg solves, but the inverse, disaggregation. I don't know a direct equivalent SQL function, but not to worry, it seems my weekend effort on another thread wasn't wasted because I can see a very simple variation on one of the solutions there that will solve this one very efficiently. It uses the model clause to iterate over the commas without any regular expression functions, XML, tree walks etc. to slow it down, and this approach should work for many similar problems. I'll add an id column so we know where the rows came from and a subid for ordering (you can drop them if you like), and an extra test record with no comma.
    CREATE TABLE test_otn  (id INTEGER, text VARCHAR2(4000));
    INSERT INTO test_otn VALUES (1, '11,12,14,16,13,18,17');
    INSERT INTO test_otn VALUES (2, '11,12,13,15,16,17,18,19,20,30');
    INSERT INTO test_otn VALUES (3, '99');
    INSERT INTO test_otn VALUES (4, '11,20,30,40,67,90,87,65,76,43,23,56,78,90,12,22,34');
    SELECT id, numid, num
      FROM test_otn
    MODEL
        PARTITION BY (id)
        DIMENSION BY (0 i)
        MEASURES (0 compos, 0 nxtpos, text, 0 numid, CAST ('' AS VARCHAR2(5)) num)
        RULES
        ITERATE (100) UNTIL compos[0] = 0
           nxtpos[0] = Instr (text[0], ',', compos[0] + 1, 1),
           num[ITERATION_NUMBER] = CASE WHEN nxtpos[0] = 0 THEN Substr (text[0], compos[0]+1)
                                        ELSE Substr (text[0], compos[0] + 1, nxtpos[0] - compos[0] - 1) END,
           numid[ITERATION_NUMBER] = ITERATION_NUMBER + 1,
           compos[0] = nxtpos[0]
    ORDER BY 1, 2
      ID      NUMID NUM
       1          1 11
                  2 12
                  3 14
                  4 16
                  5 13
                  6 18
                  7 17
       2          1 11
                  2 12
                  3 13
                  4 15
                  5 16
                  6 17
                  7 18
                  8 19
                  9 20
                 10 30
       3          1 99
       4          1 11
                  2 20
                  3 30
                  4 40
                  5 67
                  6 90
                  7 87
                  8 65
                  9 76
                 10 43
                 11 23
                 12 56
                 13 78
                 14 90
                 15 12
                 16 22
                 17 34
    35 rows selected.

  • Distinct Records Selection in Crystal 11

    Need to select Distinct Records only, but the drop down under 'Database' shows the 'Select Distinct Records' option grayed out.  Why does Crystal do that, and how may I eliminate duplicate records?  Thanks!

    Hi Brian,
    This issue normally comes when there are multiple datasources being used. For example if you are using two databases, like Oracle and MS Access to fetch data, the "Select Dictinct Records" will be greyed out.
    In this case, you might want to write a query in the Add Command option which select distinct records.
    If you are using only one database, then check if you are able to select "Select Dinstinct Records" in the Database menu.
    Please let us know if this helps.
    Regards,
    Abhishek.

  • Get Distinct records with a condition

    I have a table with multiple records per Person and an active status column. I would like to fetch distinct records by PersonID and PersonName but also return active status with a condition that if person is active on at least one he is considered active.
    Here is my table.
    DECLARE @Person TABLE (PersonID INT, PersonName VARCHAR(50), DeptName VARCHAR(50), Active bit)
    INSERT INTO @Person (PersonID, PersonName, DeptName, Active) VALUES (111, 'John', 'Finance', 0), (111, 'John', 'HR', 1),(222, 'Jack', 'Payroll', 0),(333, 'Mark', 'Facilities', 1),(444, 'Bill', 'IT', 0),(444, 'Bill', 'HR', 1),(444, 'Bill', 'Finance', 1)
    My resultset after the query should be as follows.
    (111, 'John', 1),(222,'Jack',0),(333,'Mark',1),(444,'Bill',1)
    Thanks for the help.

    >> I have a table with multiple records [sic] per Person and an active status column. <<
    Rows are not records. Tables have to have a key by definition and since they model a set, the names are plural or collective. These are fundamentals that were covered in the first few chapters of any book on RDBMS. You do not know ISO-11179 naming rules. 
    You still use assembly language bit flags in SQL! A status is a state of being so it requires a temporal component. Do you really know people with FIFTY character name? Even in Poland and India, that is not likely. But when you allow garbage data, you will
    get it. 
    Identifiers are CHAR(n), not numeric; what math do you do with them? Again, this is a fundamental of data modeling. 
    You are simply reenforcing your bad habits and not taking the time to learn how to do RDBMS correctly. 
    CREATE TABLE Personnel --- collective name!
    (person_id CHAR(3) NOT NULL,
     person_name VARCHAR(10) NOT NULL, 
     dept_name VARCHAR(10)NOT NULL, 
     hire_date DATE NOT NULL,
     termination_date DATE,
     CHECK (hire_date < termination_date),
     PRIMARY KEY (person_id, hire_date));  -- null means current.
    See how a valid design makes finding a status possible? And it shows us just what a mess you have! Bill is working in TWO departments! See how the key prevents this error? We should add more constraints, but I do not think you are ready for that yet. 
    SELECT person_id, person_name, dept_name AS current_dept_name
      FROM Personnel 
     WHERE termination_date IS NULL;
    --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

  • How can I get the number of distinct records that each field of a DB table has?

    Hi everyone,
    I would like to know how to get he number of distinct records that each field of a DB table has. When tracing a SQL statement either in ST12 or ST05, in the plan execution, if the sentence made useage of an index, then I can click in the index name and see this kind of information (no. of distinct values for each field of that index).
    Can I do something like this but with the whole fields of a table?
    What I have found until now is in Tx ST10; I search for whatever kind of table statistics and then use the function of "Analyze table" (which takes me to Tx DB05). In here, I can enter a table and up to 5 fields in order to get the information that I want.
    Is there any other way to do this?
    Regards,
    David Reza

    Hi David,
    You can export the same to excel and sort as per requirement.
    Sorry is that what you are looking for ?
    Regards,
    Deepanshu Sharma

  • Value Set whose Data come from customize table with distinct record

    Dear All,
    I am new in Oracle EBS, currently i am creating value set whose data come from customize table which have 40 duplicate record in which distinct column return 27 record .
    Table XX_ROUND_SET
    Columns (Transactions_id,set_record)
    Total Record (40)
    Distinct Record (Set_Record --> 27)
    I just want to show only 27 record in it.
    Thanks
    Rehan

    Hi Rehan,
    PL.IGNORE MY EARLIER UPDATE AND TREAT THIS UPDATE AS YOUR SOLUTION.
    Method 1
    Create the VIEW based on DISTINCT values; use the VIEW for creates the VALUESET.
    Method 2
    Paste the QUERY in TABLE field with alias name, and give the column name (with alias name).
    (in your case )
    TABLE NAME : ( select distinct transactions_id, set_record from XX_ROUND_SET ) Y
    VALUE : Y.transactions_id
    HTH
    Sanjay

  • Distinct records

    hi all,
    i am calculating sum for one column but i want sum for the distinct records from the table
    SELECT D_NUMBER,D_TYPE,SUM(D_AMT)
    FROM D_TABLE
    WHERE D_CODE =:PARAMETER
    GROUP BY D_NUMBER,D_TYPEin the above case D_NUMBER,D_TYPE may repeat i want the amount for distinct records. how can i for a query to get (tried with distinct but not getting the correct sum..
    Thanks..

    Hi,
    so you searching for something between d_number,d_type and d_amt and the sum of d_amt based on the first two. Then you need a differentiator, how do you do make the first 2 distinct based on some other column, so these 3 will be distinct, otherwise it will not be possible, except if you say the first 3 rows belong together, and that is what I want to be summed.
    Herald ten Dam
    htendam.wordpress.com

  • Recording help needed

    recording help needed. I'm a beginner, imac, logic express and helix board 12 firewire.
    I have recorded my daughter voice only ok, BUT when i import audio file to track 1 as backing track and my daughter is using headphones from the helixboard to sing to she does not record to track 2 when all in enabled.
    Should her headphone come from the imac and not the helix board
    Regards
    Paul

    Check the recording channel in the channel strip.
    It must be set the same as the audio interface channel.
    cheers
    rob

  • Need help in SQL query to get only distinct records

    Hi all.
    I am new to oracle SQL and i want to write a query to get only distinct values from 2 tables.
    for example i hade 2 tables table1(employee_id,employee_no,grade) and another table2 with same structure.
    for example data in table1 is
    Employeeid employeeno Grade
    1 101 A
    1 101 B
    1 101 E
    1 101 D
    and data in table 2 is
    Employeeid employeeno Grade
    1 101 A
    1 101 B
    1 101 E
    i want to display only the fourth row like the data that doesnt exist in table2 i,e (1 101 D)
    I had too much records in both tables and i jst want to see the records that is in table 1 not in table 2 only.
    employeeid and employeeno are the same in both tables
    I hope u understand my query. I user left outer join and right outer join bt it displays all the results that and matching and unmatching. I want jst unmatched records.
    Any help is highly Appreciated.
    Thanx in Advance.
    I am using oracle 10G on windows

    Try MINUS:
    http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/queries004.htm#i2054381
    SQL> -- generating sample data:
    SQL> with t1 as (
      2  select 1 employeeid, 101 employeeno, 'A' grade from dual union
      3  select 1, 101, 'B' from dual union
      4  select 1, 101, 'E' from dual union
      5  select 1, 101, 'D' from dual
      6  )
      7  ,  t2 as (
      8  select 1 employeeid, 101 employeeno, 'A' grade from dual union
      9  select 1, 101, 'B' from dual union
    10  select 1, 101, 'E' from dual
    11  )
    12  --
    13  -- actual query:
    14  --
    15  select employeeid
    16  ,      employeeno
    17  ,      grade
    18  from   t1
    19  minus
    20  select employeeid
    21  ,      employeeno
    22  ,      grade
    23  from   t2;
    EMPLOYEEID EMPLOYEENO G
             1        101 D
    1 row selected.

  • Microphone is no longer recording -- help nee

    Hello. I have a Sound Blaster Li've! 24-bit sound card. I used to be able to record with my microphone which is hooked up to a pre-amplifier which is hooked up to the sound card's recording port on the back of my PC. Then, in the summer, I wasnt able to record anymore. I updated all the drivers, and reinstalled the sound card and neither fixed it. Therefore, I assumed that my problem was that maybe the preamp, the cables, and/or microphone weren't working. So I bought entirely new equipment for everything, and it still doesn't record!!! I looked at the FAQ in this forum and I followed everything, and tried some of the suggestions multiple times and it still does not record. I also did a search on the forums and seems like other people's similar problems were not resolved. I can't hear any of the microphone output through my headphones either. My sound card is working fine otherwise.
    One strange thing that I noticed is that I CAN hear my microphone output for about three seconds every time i reinstall/update the drivers for the Sound Blaster Li've! sound card This occurs DURING the update. Im wondering if there is another program that is possibly blocking the recording or if something is corrupting certain driver(s)? Would there be anyway to check this? Is there something else that could be wrong?
    Is there anyway to fix the problem without having to repartition my hard dri've? :help:

    bump

Maybe you are looking for