locked
selecting distinct for 1 column only RRS feed

  • Question

  • User-1106823036 posted

    I have the following table:

    Id |   Author_En |   Author_Ar
    
    ---------------------------------
    
    1| test               | testing
    
    2| name               |naming
    

    what I want to obtain is the below:

    Id |   Author_En |   Author_Ar
    
    ---------------------------------
    
    1| test               | testing
    
    2| name               |naming
    
    

    so distinct only by Author_en because sometimes I have null values for Author_Ar

    In other words I want all unique Author_En with their relative Author_AR

    Tuesday, February 23, 2016 7:59 AM

Answers

  • User-219423983 posted

    Hi lolo512,

    lolo512

    so distinct only by Author_en because sometimes I have null values for Author_Ar

    In other words I want all unique Author_En with their relative Author_AR

    You could have a look at the below code. If it’s not what you want, I suggest you’d better share more initial data and show the expected output, so that I could know more clear about what you want to achieve. Besides, could you clarify why do you want to achieve the result with distinct for 1 column only? If you implement the need with below code, it would be easy to get all unique “Author_En” and “Author_Ar”.

    declare @tmp table (id int, Author_En varchar(20),  Author_Ar varchar(20))
    insert into @tmp values (1, 'test','testing')
    insert into @tmp values (2, 'name','naming')
    insert into @tmp values (3, 'test',null)
    
    select * from @tmp
    
    select distinct Author_En, Author_Ar
    from @tmp
    where Author_Ar is not null
    

    Best Regards,

    Weibo Zhang

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, February 23, 2016 8:37 AM