Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL query help 1

Status
Not open for further replies.

wmconlon

Technical User
Jul 10, 2003
2
US
I picked my SQL in the street, so it's kind of rudimentary. Maybe someone can point me in the right direction.

Here's a table

document characteristic
1 a
1 b
1 d
2 a
2 d
2 e
3 a
3 b

I want to SELECT the document(s) that match each of a set of characteristics.

Say I want all documents that have both characteristic a AND b: This should return documents 1 and 3

Likewise, requesting characteristics a AND d returns documents 1 and 2

Say I request characteristics b AND d: I should get no rows.

thanks
 
Code:
select document
from t
 where characteristic in ('a','d')
 group by document
 having count(*) = 2 -- this corresonds to the number 
                     -- of items in the in clause
 
swampBoogie:
merci. works great.

sleipner214:
correct. I mistyped case 3, but fortunately the -esp switch worked.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top