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 MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Create query with multiple criteria from a many to many relationship 2

Status
Not open for further replies.

dmuroff

MIS
Aug 15, 2004
143
CA
Alright I've been picking my brain for the past hour trying to figure this one out...

I have 3 tables...
1) Retailers-RetailerID, RetailerName, address etc. (500 entries)
2) Distributors- DistributorID, DistName (10 entries)
3) Uses- RetailerID, DistributorID

Sample data is as follows for Distribution table:
RetailerID DistributorID
1 1
1 3
2 1
2 6
3 4
3 5
4 8

I am trying to create a query which will give return retailer information for those retailer who use multiple distributors.

I have tried the following but I have been unsuccessful:

SELECT Uses.DistributorID, Uses.RetailerID
FROM Uses
WHERE ((Uses.DistributorID)=1 And (Uses.DistributorID)=2);

Is this possible to accomplish with the way I designed this database? Thanks!
 
One last thing...

Is there a simple way to adapt this to query the records that use for example DistributorID 1 AND DistributorID 4?
The following code does the trick
Code:
SELECT Uses.DistributorID, Uses.RetailerID
FROM Uses
WHERE DistributorID IN (1, 4)
HAVING Count(DistributorID) > 1
But I am using a search form and I am wondering if there's a way to alter the code from your last post in order to avoid using If statements in the SQL.

Thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top