SELECT DISTINCT

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Keith

    SELECT DISTINCT

    I don't know what the correct syntax is to do what I want with the DISTINCT
    function (if it's actually possible).

    I have a query which displays a variety of fields from a variety of tables
    (pretty standard).

    However, I only want to show records where the contents of one particular
    column in the query are unique - I do not want to perform the function on
    the entire record because other fields in the records may be duplicated for
    as reason.


  • Viktor Pryganov

    #2
    Re: SELECT DISTINCT

    Hi, Keith!
    You wrote on Wed, 12 May 2004 10:46:55 +0100:

    K> I don't know what the correct syntax is to do what I want with the
    K> DISTINCT function (if it's actually possible).
    K> I have a query which displays a variety of fields from a variety of
    K> tables (pretty standard).
    K> However, I only want to show records where the contents of one
    K> particular column in the query are unique - I do not want to perform
    K> the function on the entire record because other fields in the records
    K> may be duplicated for as reason.

    may be you should try GROUP BY.
    but.. how do you want to present not unique fileds? - for them use aggregate
    functions.
    here is a some example:
    SELECT a.user_id, MAX(ref.name), ...
    FROM sometbl a, reftbl ref, ...
    GROUP BY a.user_id

    in this case set of your records will contain only unique values of
    'user_id', others fields will
    be calculated by agg. functions.

    -
    exexe


    Comment

    • Simon Hayes

      #3
      Re: SELECT DISTINCT


      "Keith" <@.> wrote in message news:nomoc.2243 $wI4.233273@war ds.force9.net.. .[color=blue]
      > I don't know what the correct syntax is to do what I want with the[/color]
      DISTINCT[color=blue]
      > function (if it's actually possible).
      >
      > I have a query which displays a variety of fields from a variety of tables
      > (pretty standard).
      >
      > However, I only want to show records where the contents of one particular
      > column in the query are unique - I do not want to perform the function on
      > the entire record because other fields in the records may be duplicated[/color]
      for[color=blue]
      > as reason.
      >
      >[/color]

      I think this may be what you want:

      select MyColumn
      from dbo.MyTable
      group by MyColumn
      having count(*) = 1

      Simon


      Comment

      Working...