Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2010
    Posts
    40

    Question Unanswered: distinct in group statement

    Hi,
    I am trying to write 2 SQL queries. One returns a detailed list of stuff while the other summarizes the results. The problem is, I am forced to use 'distinct' in the first, detailed query but can't seem to use it in the summary one.

    For example

    select distinct on (callid) * from calls where blah is blah

    select count(1) , name from calls group by name

    My detailed SQL is correct but my summary counts the duplicates so it is off. If I use the distinct in the summary SQL, it wants me to group by callid which kills what I'm trying to do.

    Any help is appreciated.

  2. #2
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Code:
    SELECT Count(DISTINCT field_name)
    ...
    George
    Home | Blog

Posting Permissions

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