Results 1 to 2 of 2

Thread: Select min(count(...)) ???

  1. #1

    Thread Starter
    PowerPoster rjlohan's Avatar
    Join Date
    Sep 2001
    Location
    Sydney, Australia
    Posts
    3,205

    Select min(count(...)) ???

    I need a query which will select from a table a distinct row respresenting the rows which have the least number of occurrences...

    e.g:

    A 1
    A 2
    B 1
    B 2
    B 3
    C 1
    C 2
    C 3
    C 4
    D 1
    D 2
    E 1
    E 2
    E 3
    F 1
    F 2


    From the above data set I would get back:
    A
    D
    F

    as each of these letters appears the least number of times (2) in the table.

    I am stuck on this one...
    -----------------------------------------
    -RJ
    [email protected]
    -----------------------------------------

  2. #2
    PowerPoster abhijit's Avatar
    Join Date
    Jun 1999
    Location
    Chit Chat Forum.
    Posts
    3,228
    Hi,
    I got upto this query

    PHP Code:
    select count(aCAA From Alphabet Group By A
    Having count
    (a) = 3
    order by A 
    However as you may have noticed I have hard-coded 3. There should be a way to get this number in that "having clause" and you will solve your problem.

    Cheers!
    Abhijit

Posting Permissions

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



Click Here to Expand Forum to Full Width