Select distinct value

HI all
DESC CLAIMS
CLAIM_NUMBER NUMBER(10)
VERSION          NUMBER(2)
STATUS          NUMBER(1) to every claim_number can be 3 statuses
0/9/1
there must be at least 1 status
Select CLAIM_NUMBER   ,STATUS  from claims
order by CLAIM_NUMBER,STATUS
CLAIM_NUMBER   STATUS
6971700            1
6971700            1
6971700            0
8624300            9
10071200          1
10453800          0
10453800          0 I want to fetch only CLAIM_NUMBER that contain only one value status
like CLAIM_NUMBER = 10453800 (which contain only 0 )
10071200 (which contain only 1)
8624300 (which contain only 9)
i started a query like this
select CLAIM_NUMBER
from CLAIMS
group by CLAIM_NUMBER
having count(distinct(status)) <  2 the problem is that i want to add to the condition the status value like 9 or 0
how shall i do that ?
thanks in advanced
Naama

is this what you are looking for?
select p.*from
select CLAIM_NUMBER,STATUS,count(distinct(STATUS)) over(partition by CLAIM_NUMBER) cnt
from CLAIMS
)p
where p.cnt =1
and status=0

Similar Messages

  • Need of SQL query in selecting distinct values from two tables

    hi,
    I need a query for selecting distinct values from two tables with one condition.
    for eg:
    there are two tables a & b.
    in table a there are values like age,sex,name,empno and in table b valuses are such as age,salary,DOJ,empno.
    here what i need is with the help of empno as unique field,i need to select distinct values from two tables (ie) except age.
    can anybody please help me.
    Thanks in advance,
    Ratheesh

    Not sure what you mean either, but perhaps this will start a dialog:
    SELECT DISTINCT a.empno,
                    a.name,
                    a.sex,
                    b.salary,
                    b.doj
    FROM    a,
            b
    WHERE   a.empno = b.empno;Greg

  • How to select distinct values from a table when it has composite primary ke

    Hi
    I have the requirement like , I need to select distinct one column values from the table which has composite primary key. How to acheive this functioinality using view object.
    Eg : Table 1 has col1 and col2, col3
    col1 col2 col3
    1 A NA
    1 B NA
    2 A NA
    3 C NA
    2 D NA
    primary key (col1,col2)
    I have to select distinct col1.
    Thanks

    Hi
    I got the solution for above. By Creating the read only view object we can acheive this.
    thanks

  • Select distinct values for ssrs sharepoint parameter

    hi,
    I need distinct selected values for parameter dropdown in shaepoint ssrs. Everrything will work fine if i select value and label field same field like(Location_Code). But i need value field to be different field (LocationID). like (dropdown id in value field
    and text as lable field)
    Because i am using value field in record filtering.
    Any suggestions?
    Thanks Manohara R

    Hi Manohar,
    Pls check the lin
    http://social.msdn.microsoft.com/Forums/sqlserver/en-US/6495db18-a1c1-480b-8c92-89c74ee47cf5/how-to-get-distinct-values-of-sharepoint-column-using-ssrs?forum=sqlreportingservices
    Please remember to click 'Mark as Answer' on the answer if it helps you

  • Best way to select distinct values based on another column?

    I have a table with three columns: id (NUMBER), data_dt (DATE), and data_value (NUMBER).
    There is a primary key on id and data_dt.
    I want to select the record with the latest data_dt for each unique id.
    What is the best way to do this?
    I have three different methods, but there may be something I am missing.
    First:
    SELECT *
    FROM
      SELECT id, data_dt, data_value,
             FIRST_VALUE(data_dt)
             OVER (PARTITION BY id ORDER BY data_dt DESC) AS last_data_dt
      FROM the_table
    WHERE data_dt = last_data_dt;(I use ORDER BY...DESC instead of just ORDER BY so I don't need the ROWS BETWEEN clause)
    Second:
    SELECT t1.*
    FROM the_table t1
    JOIN
      SELECT id, MAX(data_dt) AS last_data_dt
      FROM the_table
      GROUP BY id
    ) t2 ON (t2.id = t1.id AND t2.data_dt = t1.data_dt);Third:
    SELECT t1.*
    FROM the_table t1
    WHERE t1.data_dt =
      SELECT MAX(t2.data_dt)
      FROM the_table t2
      WHERE t2.id = t1.id
    );-- Don

    Hi,
    There are more possible scenario's, for example:
    select t1.*
    from   the_table t1
    where not exists ( select null
                       from   the_table t2
                       and    t2.data_dt > t1.data_dt
    What is the best way to do this?Only you can tell:
    Test all scenario's, check the execution plans, set timing on and pick the best/fastest one ;-)
    If it's not clear, please post the execution plans here.

  • OBI columns not showing distinct values.

    Hi,
    Please help me out with the below issue.
    I have a colulmn called Product Type. Same column is been pulled into many subject areas. In one of the subject area the column when checked for all product types, it is not showing distinct values, instead it displays multiple rows of sinlge value. Whereas in other subject areas it dsiplays distinct values.
    So please help me out on this issue.
    Thanks,
    Rajesh S

    Hi,
    I don't think it's not an issue with not selecting "Select Distinct Value" checkbox .. because same column pulled into to other subject areas working fine. But here also sometimes it shows correct distinct value and sometimes all values(Duplicate values).
    Thanks,
    Rajesh.

  • Select records based on first n distinct values of column

    I need to write a query in plsql to select records for first 3 distinct values of a single column (below example, ID )and all the rows for next 3 distinct values of the column and so on till the end of count of distinct values of a column.
    eg:
    ID name age
    1 abc 10
    1 def 20
    2 ghi 10
    2 jkl 20
    2 mno 60
    3 pqr 10
    4 rst 10
    4 tuv 10
    5 vwx 10
    6 xyz 10
    6 hij 10
    7 lmn 10
    so on... (till some count)
    Result should be
    Query 1 should result --->
    ID name age
    1 abc 10
    1 def 20
    2 ghi 10
    2 jkl 20
    2 mno 60
    3 pqr 10
    query 2 should result -->
    4 rst 10
    4 tuv 10
    5 vwx 10
    6 xyz 10
    6 hij 10
    query 3 should result -->
    7 lmn 10
    9 .. ..
    so on..
    How to write a query for this inside a loop.

    Hi,
    So, one group will consist of the lowest id value, the 2nd lowest and the 3rd lowest, reggardless of how many rows are involved. The next group will consist of the 4th lowest id, the 5th lowest and the 6th lowest. To do that, you need to assign numbers 1, 2, 3, 4, 5, 6, ... to the rows in order by id, with all rows having the same id getting the same number, and without skipping any numbers.
    That sounds like a job for the analytic DENSE_RANK function:
    WITH     got_grp_id     AS
         SELECT     id, name, age
         ,     CEIL ( DENSE_RANK () OVER (ORDER BY id)
                   / 3
                   )          AS grp_id
         FROM     table_x
    SELECT     id, name, age
    FROM     got_grp_id
    WHERE     id     = 1     -- or whatever number you want
    ;If you'd care to post CREATE TABLE and INSERT statements for your sample data, then I could test it.
    See the forum FAQ {message:id=9360002}

  • Query help in select Distinct on one column.

    CREATE GLOBAL TEMPORARY TABLE Table1 (
    ID1 varchar2(100) ,
    Name1 varchar2(100),
    Name11 varchar2(100)
    insert into Table1 values ('a','n1','h3');
    insert into Table1 values('b','n2','h2');
    insert into Table1 values('a','n3','h1');
    insert into Table1 values('c','n4','h5');
    insert into Table1 values ('c','n5','h4');
    insert into Table1 values('d','n6','h6');
    select * from Table1;
    ID1,NAME1,     NAME11
    a,     n1,     h3
    b,     n2,     h2
    a,     n3,     h1
    c,     n4,     h5
    c,     n5,     h4
    d,     n6,     h6
    I am trying to select distinct ID1 and all values associated with it which is max row.I want to result as -
    ID1,NAME1,     NAME11
    a,     n3,     h1
    b,     n2,     h2
    c,     n5,     h4
    d,     n6,     h6
    Can you please help me to write simple query to get above result.
    Edited by: 871447 on Jul 25, 2011 9:42 AM
    Edited by: 871447 on Jul 25, 2011 9:45 AM

    Hi,
    Do a self-join, to combine the two rows for each value of id1 onto one output row.
    Make it an outer join, in case there is only one row with a vlaue for id1.
    SELECT  l.id1
    ,     l.name1
    ,     NVL ( r.name11
             , l.name11
             )          AS name11
    FROM              table1     l
    LEFT OUTER JOIN     table1     r  ON  l.id1     = r.id1
                              AND l.name1     < r.name1
    ;Edited by: Frank Kulash on Jul 25, 2011 12:57 PM
    Sorry, I mis-read the problem.
    Lee's solution, above, assumes that name1 is unique, as it is in your sample data.
    What output would you want if that's not the case?
    If name1 is not unique, but the combination of (id1, name1) is unique, then you can modify Lee's solution like this:
    SELECT  *
    FROM    table1
    WHERE   (id1, name1) IN (
                        SELECT    id1
                        ,       MAX (name1)
                               FROM          table1
                        GROUP BY  id1
    ;Or, if you can't make any assumptions about uniqueness, you might need something like this:
    WITH     got_r_num     AS
         SELECT  id1, name1, name11
         ,     ROW_NUMBER () OVER ( PARTITION BY  id1
                                   ORDER BY          name1     DESC
                             ,                name11     DESC
                           )      AS r_num
         FROM     table1
    SELECT  id1, name1, name11
    FROM     got_r_num
    WHERE     r_num     = 1
    ;

  • "How to get distinct values of sharepoint column using SSRS"

    Hi,
        I have integrated sharepoint list data to SQL Server reporting services. I am using the below to query sharepoint list data using sql reporting services.
    <Query>
       <SoapAction>http://schemas.microsoft.com/sharepoint/soap/GetListItems</SoapAction>
       <Method Namespace="http://schemas.microsoft.com/sharepoint/soap/" Name="GetListItems">
          <Parameters>
             <Parameter Name="listName">
                <DefaultValue>{GUID of list}</DefaultValue>
             </Parameter>
             <Parameter Name="viewName">
                <DefaultValue>{GUID of listview}</DefaultValue>
             </Parameter>
             <Parameter Name="rowLimit">
                <DefaultValue>9999</DefaultValue>
             </Parameter>           
          </Parameters>
       </Method>  
    <ElementPath IgnoreNamespaces="True">*</ElementPath>
    </Query>
    By using this query, I am getting a dataset which includes all the columns of sharepoint list. Among these columns, I wanted to display only 2 columns (i.e Region and Sales type) using chart. I have created a Region parameter but when I click preview, the drop down box is giving me all the repeatative values of region like RG1,RG1,RG1,RG2,RG2,RG2,RG2,RG3.......... I wanted to display only distinct values of Region parameter so that whenever end user select region from the parameter drop down, it will display the respective value of Sales type column.
    Also when I select only RG1 parameter, it is giving me a chart including the sales type of all the Regions. (it should display me only the sales type of RG1) How can I link these 2 columns so that they will display the values respectively.
              I would really appreciate if anyone can help me out with this.
    Thanks,
    Sam.

    Hi Sam,
    By code, the CAML language doesn’t have any reserved word (or tag) to set this particular filter to remove duplicate results.
    In this case, we could use the custom code to get distinct records.
    Here are the detailed steps:
    1.         Create a hidden parameter that gets all the records in one field.
    Note: Please create another dataset that is same of the main dataset. This dataset is used for the parameter.
    2.         Create a function that used to remove the duplicate records.
    Here is the code:
    Public Shared Function RemoveDups(ByVal items As String) As String
    Dim noDups As New System.Collections.ArrayList()
    Dim SpStr
    SpStr = Split(items ,",")
    For i As Integer=0 To Ubound(Spstr)
    If Not noDups.Contains(SpStr(i).Trim()) Then
    noDups.Add(SpStr(i).Trim())
    End If
    Next
    Dim uniqueItems As String() = New String(noDups.Count-1){}
    noDups.CopyTo(uniqueItems)
    Return String.Join(",", uniqueItems)
    End Function
    3.         Create another parameter that will be used for filtering the maindata.
    Please set the available value to be =Split(Code.RemoveDups(JOIN(Parameters!ISSUE_STATUS_TEMP.Value, ",")), ",")
    And the default value to be the value you what such as the first value:
    =Split(Code.RemoveDups(JOIN(Parameters!ISSUE_STATUS_TEMP.Value, ",")), ",").(0)
    4.         Go to the main dataset. Open the property window of this dataset.
    5.         In the “Filters” tab, set the filter to be:
    Expression: <The field to be filter>
    Operator: =
    Value: =Parameters!Region.Value
    The parameter “Region” should be the parameter we created in the step3.
    Now, we should get distinct values of SharePoint columns.
    If there is anything unclear, please feel free to ask.
    Thanks,
    Jin
    Jin Chen - MSFT

  • Get distinct values from plsql array

    Hi,
    I have declared a variable as below in plsql proc.
    type t_itemid is table of varchar2(10);
    inserted set of items in to this using a program
    now i want distinct values from that array how can i get it.

    I am using 9i so i cannot use set operator and more over my problem is that i am declaring the variable inside the plsql block . when i tried i am getting the below errors:
    SQL> r
    1 declare
    2 type t_type is table of varchar2(10);
    3 v_type t_type;
    4 begin
    5 v_type := t_type('toys','story','good','good','toys','story','dupe','dupe');
    6 for i in (select column_value from table(v_type)) loop
    7 dbms_output.put_line(i.column_value);
    8 end loop;
    9* end;
    for i in (select column_value from table(v_type)) loop
    ERROR at line 6:
    ORA-06550: line 6, column 41:
    PLS-00642: local collection types not allowed in SQL statements
    ORA-06550: line 6, column 35:
    PL/SQL: ORA-22905: cannot access rows from a non-nested table item
    ORA-06550: line 6, column 10:
    PL/SQL: SQL Statement ignored
    ORA-06550: line 7, column 22:
    PLS-00364: loop index variable 'I' use is invalid
    ORA-06550: line 7, column 1:
    PL/SQL: Statement ignored

  • CE function to get distinct values from Column table

    Hi All,
    Could you please let me know the appropriate CE function to get the distinct values from column table.
    IT_WORK = SELECT DISTINCT AUFNR FROM :IT_WO_DETAILS;
    Thank you.

    Hi,
    If you have 10g, you can use Model( with model performance is better than connect by )
    Solution
    ========================================================================
    WITH t AS
    (SELECT '0989.726332, 1234.567432, 3453.736379, 3453.736379, 0989.726332, 3453.736379, 1234.567432, 1234.567432, 0989.726332'
    txt
    FROM DUAL)
    SELECT DISTINCT TRIM(CHAINE)
    FROM T
    MODEL
    RETURN UPDATED ROWS
    DIMENSION BY (0 POSITION)
    MEASURES (CAST( ' ' AS VARCHAR2(50)) AS CHAINE ,txt ,LENGTH(REGEXP_REPLACE(txt,'[^,]+',''))+1 NB_MOT)
    RULES
    (CHAINE[FOR POSITION FROM  1 TO NVL(NB_MOT[0],1) INCREMENT 1] =
    CASE WHEN NB_MOT[0] IS NULL THEN TXT[0] ELSE REGEXP_SUBSTR(txt[0],'[^,]+',1,CV(POSITION)) END );
    =========================================================================
    Demo
    =======================================================================
    SQL> WITH t AS
    2 (SELECT '0989.726332, 1234.567432, 3453.736379, 3453.736379, 0989.726332, 3453.736379, 123
    4.567432, 1234.567432, 0989.726332'
    3 txt
    4 FROM DUAL)
    5 SELECT DISTINCT TRIM(CHAINE)
    6 FROM T
    7 MODEL
    8 RETURN UPDATED ROWS
    9 DIMENSION BY (0 POSITION)
    10 MEASURES (CAST( ' ' AS VARCHAR2(50)) AS CHAINE ,txt ,LENGTH(REGEXP_REPLACE(txt,'[^,]+',''))+1 NB_MOT)
    11 RULES
    12 (CHAINE[FOR POSITION FROM  1 TO NVL(NB_MOT[0],1) INCREMENT 1] =
    13 CASE WHEN NB_MOT[0] IS NULL THEN TXT[0] ELSE REGEXP_SUBSTR(txt[0],'[^,]+',1,CV(POSITION)) END );
    TRIM(CHAINE)
    3453.736379
    1234.567432
    0989.726332
    SQL>
    ========================================================================

  • How to get Distinct Values from Answers

    Hi,
    How to get Distinct values from answers, i've tried to put some functions on it.
    Thanks,
    Malli

    Malli,
    Are you trying to fetch data from Dimension Attr OR Fact Measures? Did you try the advance tab - > Advanced SQL Clauses - > Check this box to issue an explicit Select Distinct.

  • How to create a table with distinct values ?

    I want to create a new table based on an existing table distinct values only, how can I avoid to create the duplicate values ?
    e.g.
    table1
    field1 field2
    0001 ABD
    0001 ABD
    0002 DCF
    0002 DCF
    new table
    field1 field2
    0001 ABD
    0002 DCF
    thanks

    create table table2
    as
    select distinct field1,field2
    from table1

  • Select Distinct and join in ODI

    Hi,
    I have following task to perform: I am loading metadata into Planning dimension from Oracle database. I have two tables
    1. "Sales"
    Columns: Name, Number, Value
    Sample Data:
    Product 1, 10, 200
    Product 2, 30, 100,
    Product 1, 15, 500
    2. P&R
    Columns:
    Name, Alias
    Product 1, SampleSoda1
    Product 2, SampleSoda2,
    Resource 1, CanForSoda,
    Resource 2, CO2
    What I need to do is: I have to select name and alias from second table of all products that were sold.
    So I need to select distinct Name from Table 1, naxt join it with Table 2 (so I have Name and Alias) and load it to planning.
    I am a little confused how to do it.
    Any help would be great!
    Best regards,
    Greg

    Hi Greg,
    What you can do is either :
    - Create a yellow interface with your table Sales as source. Map the name column directly in the target. In the flow tab, click on your target and select "Distinct rows".
    - Create a second interface, with your first interface as source. Select the "Use Temporary Interface as Derived Table (Sub-Select)" checkbox.
    - Add your second datastore and join it. Or you can use a lookup table.
    OR
    - Create an interface with Sales and P&R as source (or set P&R as a lookup table).
    - Go on the flow tab and select "Distinct rows".
    If you've a lot a data in the first table, I would go for the first solution.
    Hope it helps.
    Regards,
    JeromeFr
    Edited by: JeromeFr on Feb 14, 2013 9:52 AM
    To be more clear in the first step of solution 1

  • Display Distinct values in LightSwitch browse screen

    i have one browse screen which is fetching value from one entity(Attached to SQL datasource), the entity will look like the below snapshot.
    ID
    EMP ID
    Emp Name
    Age
    Role
    1
    266
    Srikanth
    26
    Developer
    2
    266
    Srikanth
    26
    Architect
    3
    122
    Raj
    29
    Tester
    4
    122
    Raj
    29
    Manager
    So in the browse screen its coming with all row values (1,2,3 and 4) even though i removed the Role field from the screen. I want to display only the distinct Emp ID, Name, Age in the browse screen of this entity. Please
    give me some suggestion.

    i suggest to Create new View Return Only Distinct record from Original Table And Update your DataSource with this view And Create Your Browse Screen Depends on This View
    SQL Script
    Create View VwEmployeeDistenct
     as 
    select Distinct  [EMP ID], [Emp Name],
    [Age]  from OrginalEmplyeeTable 
    go

Maybe you are looking for

  • How do I change the color of the back and forward arrow to green

    In Windows 7 the color of the back and forward page arrow is blue. On my desktop computer using Windows XP the color of the back and forward page arrow is green. This is much easier on my eyes. Is there a way to change the color to green in Windows 7

  • SBWP inbox not receiving mails

    Hi Team , I have a query , two sap user ids say A and B .i am sending mails to sap inbox for both the users A and B . A user is receiving mails in documents but B is not receiving any documents ...in workflow log the step executed succesfully.. when

  • Sending RFC to WS with HTTPS

    hello I have a scenario RFC to WS synchronic with HTTPS. when connection to the WS I am recieving an error (see below) it looks like a problem in the MUST UNDERSTAND parameter. does any one know this problem and know how to solve it? Exception Data :

  • How to set permission levels per site collection

    Hello, A site collection would have 700 sites , with the same (new) permission levels. Is there a way (apart from programming) to copy these permission levels? Thank you. Christos

  • In consignment fillup is it necessary the excise duty?

    Hi experts,                  In the consignment sales when we are doing consignment fill up is it necessary Excise invoice? Is it possible Excise invoice without billing?