SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Zealot fatnic's Avatar
    Join Date
    Aug 2006
    Location
    Lincoln, UK
    Posts
    191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    problem with HAVING

    Hi.

    I'm currently developing a dreamteam website. When a player selection is made on the page it sends a list of currently selected players codes to my script and I then need it to calculate which players can be selected

    the table structure looks like
    Code:
    code | name | position | club | price
    I need to return a list of clubs that have been selected twice already.

    So far I can use
    Code:
    SELECT club 
    FROM players
    WHERE code IN (001,002,003,004,005,006,007,008,009,010,011)
    to select a list of already selected players but how can I filter it down to clubs that have been picked twice?

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,323
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    SELECT club
    FROM players
    WHERE code IN (001,002,003,004,005,006,007,008,009,010,011)
    GROUP BY club
    HAVING COUNT(*) = 2


    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"


Bookmarks

Posting Permissions

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