select distinct values

  • Hi,

    Can anyone please help me

    I want the answer for this in SQL Server 2000.

    I have a table containing fields as Name and Salary.Name is varchar data type and Salary int data type.

    I want to eliminate duplicate records.

    A 12000

    B 15000

    C 13000

    A 12000

    A 12000

    B 15000

    C 13000

    B 15000

    A 12000

    I want the result as

    A 12000

    B 15000

    C 13000

    Thanks in advance

     

  • There are two options here.

    select distinct field1, field2

    from table

    or

    select field1, field2

    from table

    group by field1, field2

    Option 1 is the better for performance if you have a large table

  • That is fine

    But I want to get the duplicate records deleted from my table

    and get the final result

    how is this possible in sql 2000

    Thanks

  • select distinct name,salary

    into #temptab

    from tablename

     

    truncate table tablename

     

    insert into tablename

    select name,salary from #temptab

     

    regards

  • Thanks Sanjay.

    It is working fine

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply