Results 1 to 5 of 5
  1. #1
    Join Date
    Aug 2008
    Posts
    9

    SQL query problem?

    I have a mental block on how to construct a SQL query, and I'm hoping somebody can help me.

    The table is...
    Code:
         Expert       Tool
            A            1
            A            2
            B            1
            B            3
            C            2
            C            4
    I want to return a list of Expert values only for those experts linked to both Tool '1' and Tool '2', i.e. expert 'A'.

    Any suggestions?

    TIA

    .... davout

  2. #2
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    Assuming (Expert,Tool) is a key
    Code:
    SELECT Expert 
    FROM myT
    WHERE Tool IN (1, 2)
    GROUP BY Expert
    HAVING COUNT(*) = 2
    Testimonial:
    pootle flump
    ur codings are working excelent.

  3. #3
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    ...or, assuming it is not:
    Code:
    SELECT Expert 
    FROM myT
    WHERE Tool IN (1, 2)
    GROUP BY Expert
    HAVING COUNT(distinct Tool) = 2
    If it's not practically useful, then it's practically useless.

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

  4. #4
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    Depends on the RDBMS
    Testimonial:
    pootle flump
    ur codings are working excelent.

  5. #5
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Quote Originally Posted by pootle flump
    Depends on the RDBMS
    more specifically, on whether it groks standard sql and the concept of keys

    the latter of which is incumbent upon you to inform it the details of

    hey, that made sense when i wrote it, what about when you read it?
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

Posting Permissions

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