Results 1 to 2 of 2

Thread: distinct row issue

  1. #1
    Join Date
    Jul 2004
    Location
    bay area
    Posts
    61

    distinct row issue

    Hi, all
    When I use select distinct column1, column2...column10
    from some tables, it will pull all the unique rows from the tables.
    What if I need to pull distinct column data, say column2, but it is not primary key, is it possible? That means I need to pull dinstinct column data even all the other columns are different.
    Thanks for all your opinions.

    Betty

  2. #2
    Join Date
    Feb 2003
    Location
    Aussie Land
    Posts
    114
    DISTINCT is used to eliminate duplicate values on one or more columns only, however it cannot include an arithmetic expression.
    It doesnt necessarily have to be used on the primary key or any particular column.


    create table #MyTable
    (
    f1 int null,
    f2 int null,
    f3 int null
    )
    go

    insert into #MyTable values( 1, 1, 1)
    insert into #MyTable values( 1, 1, 1)
    insert into #MyTable values( 1, 1, 1)
    insert into #MyTable values( 1, 2, 3)

    -- returns 2 rows, after eliminating duplicate values from output
    -- using the combination of columns f1, f2, and f3
    select distinct f1, f2, f3 from #MyTable

    -- returns 2 rows, after eliminating duplicate values from output
    -- using the column f2
    select distinct f2 from #MyTable

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •