what about:

select name from your_table where attributeID in (5, 11)

Obviously you'll need to construct the IN part of the query according to the
number of ID's entered by the user.

Add the word DISTINCT (after select) if you don't want the query to return
duplicate names.



-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]]
Sent: Thursday, November 04, 1999 10:20 AM
To: Multiple recipients of list database
Subject: [DUG-DB]: A tricky SQL problem




Hi, I have a tricky SQL problem (you may have guessed that from the subject
heading :) that is beyond my SQL ability. And it only involves one table.

Here is a simplified example table:

Name                AttributeID

Bob                           5
Bob                           3
Bob                           11
Jim                             5
Jim                             7
Alice                         8
Alice                          5
Alice                         11

Basically, a person can have any number of attribute ID's (possibly even the
same one twice). The query goes something like this: "Find me all the names
that
have records for AttributeID 5 and for AttributeID 11" where the 5 and the
11
will change depending on what the user is searching for. The example query
only
required 2 attributeID's to exist, but there is in fact no limit.

I'm guessing that some kind of tricky sub-query or exists clause is needed
but
every time I try and formulate it it escapes me.

Phil.


---------------------------------------------------------------------------
  New Zealand Delphi Users group - Database List - [EMAIL PROTECTED]
                  Website: http://www.delphi.org.nz
---------------------------------------------------------------------------
  New Zealand Delphi Users group - Database List - [EMAIL PROTECTED]
                  Website: http://www.delphi.org.nz

Reply via email to