If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > General > Database Concepts & Design > SQL query problem?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-23-09, 07:23
davoutuk davoutuk is offline
Registered User
 
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
Reply With Quote
  #2 (permalink)  
Old 07-23-09, 07:38
pootle flump pootle flump is offline
King of Understatement
 
Join Date: Feb 2004
Location: One Flump in One Place
Posts: 14,905
Assuming (Expert,Tool) is a key
Code:
SELECT Expert 
FROM myT
WHERE Tool IN (1, 2)
GROUP BY Expert
HAVING COUNT(*) = 2
__________________
Testimonial:
Quote:
pootle flump
ur codings are working excelent.
Reply With Quote
  #3 (permalink)  
Old 07-23-09, 09:00
blindman blindman is offline
World Class Flame Warrior
 
Join Date: Jun 2003
Location: Ohio
Posts: 11,726
...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"
Reply With Quote
  #4 (permalink)  
Old 07-23-09, 09:23
pootle flump pootle flump is offline
King of Understatement
 
Join Date: Feb 2004
Location: One Flump in One Place
Posts: 14,905
Depends on the RDBMS
__________________
Testimonial:
Quote:
pootle flump
ur codings are working excelent.
Reply With Quote
  #5 (permalink)  
Old 07-23-09, 09:53
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
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?
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On