locked
Fetching distinct records from table satisfying the conditions RRS feed

  • Question

  • Can you please help in this query

    How to fetch distinct primary column 'a' records from a table

    with a column b satisfying 2 different values 

    and column c with a specific value

    Monday, July 2, 2018 4:48 PM

Answers

  • can you post some sample data and explain what you want as output?

    do you mean something like this?

    SELECT ColA,ColB,ColC 
    FROM
    (
    SELECT *,
    ROW_NUMBER() OVER(PARTITION BY COlA ORDER BY ColA) AS Seq
    FROM TableName
    WHERE ColC = 'CValue1'
    AND ColB IN ('BValue1','BValue2')
    )t
    WHERE Seq = 1
    


    Please Mark This As Answer if it solved your issue
    Please Vote This As Helpful if it helps to solve your issue
    Visakh
    ----------------------------
    My Wiki User Page
    My MSDN Page
    My Personal Blog
    My Facebook Page

    • Marked as answer by kndtsrini Tuesday, July 3, 2018 10:38 AM
    Monday, July 2, 2018 5:12 PM
    Answerer

All replies

  • probably something like this

    select distinct A   from TableA where ColumnB in ('Value1','Value2') and ColumnC='X'

    Monday, July 2, 2018 4:59 PM
  • can you post some sample data and explain what you want as output?

    do you mean something like this?

    SELECT ColA,ColB,ColC 
    FROM
    (
    SELECT *,
    ROW_NUMBER() OVER(PARTITION BY COlA ORDER BY ColA) AS Seq
    FROM TableName
    WHERE ColC = 'CValue1'
    AND ColB IN ('BValue1','BValue2')
    )t
    WHERE Seq = 1
    


    Please Mark This As Answer if it solved your issue
    Please Vote This As Helpful if it helps to solve your issue
    Visakh
    ----------------------------
    My Wiki User Page
    My MSDN Page
    My Personal Blog
    My Facebook Page

    • Marked as answer by kndtsrini Tuesday, July 3, 2018 10:38 AM
    Monday, July 2, 2018 5:12 PM
    Answerer