Results 1 to 7 of 7

Thread: Duplication

  1. #1
    Join Date
    Dec 2004
    Posts
    7

    Unanswered: Duplication

    How can I achieve the following...
    I have a Membership No. field which comes from a bookings table, so multiple membership no. do exist. What I want to achieve is a list of membership No.s with no duplication. Sorry to be so dumb, but we all have to start somewhere.

  2. #2
    Join Date
    Nov 2004
    Location
    on the wrong server
    Posts
    8,835
    Provided Answers: 6
    Look up SELECT DISTINCT in BOOKS ONLINE

  3. #3
    Join Date
    Dec 2004
    Posts
    7
    SELECT MembershipNO, COUNT(*)
    FROM BOOKLIST
    GROUP BY MembershipNO
    HAVING COUNT(*)>1

  4. #4
    Join Date
    Dec 2004
    Posts
    7

    More detail

    Thanks for the pointer, sorry I just need the unique booking numbers?

  5. #5
    Join Date
    Dec 2004
    Posts
    7

    Thanks

    Got it sorted now

  6. #6
    Join Date
    Dec 2004
    Posts
    7

    What about this

    Thank for this is works great

    SELECT MembershipNO, COUNT(*)
    FROM BOOKLIST
    GROUP BY MembershipNO
    HAVING COUNT(*)>1


    Do you have a solution when I want to SELECT more than one field but only COUNT one of them, when I try to SELECT more than one, the count seems to lose its integrity.

  7. #7
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    You will need to use some sort of aggregate function on the additional fields to determine which of competing values you want to use:

    SELECT MembershipNO, Max([Field2]), Min(Field3]), AVG([Field4]),COUNT(*)
    FROM BOOKLIST
    GROUP BY MembershipNO
    HAVING COUNT(*)>1

    You will get one record for every distinct combination of non-aggregated fields included in your SELECT clause.
    If it's not practically useful, then it's practically useless.

    blindman
    www.chess.com: "sqlblindman"
    www.LobsterShot.blogspot.com

Posting Permissions

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