help with distinct

  • I am brain dead this morning...

    I have a table that I want to list distict phone #'s. I can do that with with:

    SELECT DISTINCT PHONENBR FROM TABLE1

    But I want to have an identifier column before the phone # column. I just need the extra id column for identification purposes.

    Is there a way to do this? My original table has an id column, but if I included that in my select statement, then I get every single record in the table, which then creates a ton of duplicate numbers.

    I know this is simple, but for some reason I am unable to figure this simple task out today...

  • you can create identity column column

    create table "table name"

    (seqi_id int identity(1,1),

    phone number bigint

    )

    Thanks

    Bhavesh

  • ROW_NUMBER()

  • Michal-469362 (9/14/2011)


    I am brain dead this morning...

    I have a table that I want to list distict phone #'s. I can do that with with:

    SELECT DISTINCT PHONENBR FROM TABLE1

    But I want to have an identifier column before the phone # column. I just need the extra id column for identification purposes.

    Is there a way to do this? My original table has an id column, but if I included that in my select statement, then I get every single record in the table, which then creates a ton of duplicate numbers.

    I know this is simple, but for some reason I am unable to figure this simple task out today...

    Do you want an existing ID from the table or just a sequential number to go with the phone number? If you just want a sequential number then you do want to use ROW_NUMBER(). If you want an ID from the table (any ID) then you use the MIN or MAX function and GROUP BY phone number.

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

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