Home Forums SQL Server 2008 T-SQL (SS2K8) which is the easy way to Eliminate the duplicates? RE: which is the easy way to Eliminate the duplicates?

  • lokesha.b (10/16/2012)


    Hi,

    Please suggest me to get the distinct values from below query

    declare @T as table(id int identity, code varchar(10))

    insert into @T(code) values('111')

    insert into @T(code) values('111')

    insert into @T(code) values('222')

    insert into @T(code) values('222')

    insert into @T(code) values('333')

    select * from @T

    I want the result as

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

    111

    222

    333

    For what you're showing, the others are correct. DISTINCT will do it.

    The real question is, what are you actually doing? I ask because the use of DISTINCT is a usual indication that a joined query was written incorrectly or the underlying database design really needs some work.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)