简体   繁体   中英

SQL Display based on count of other table

We have the following Tables:

**Product**
Productnr


**Deliverable**
Deliverernr
Productnr

**Deliverer**
Deliverernr

The relationship between Product and Deliverer is a Many to Many and the Deliverable is its junction table

I am trying to display all the products that are only delivered by ONE deliverer

I have tried the following with no success:

SELECT Product.Productnr
FROM Product, Deliverable, Deliverer
WHERE Product.Productnr = Deliverable.Productnr AND
Deliverer.Deliverernr = Deliverable.Deliverernr
HAVING COUNT(Product.Productnr) = 1;

I am using MS access

Thanks in advance for any help.

I don't know why you need to use all tables when you have one junction point and you want specific result that depends both variables of junction point, I may be wrong in getting your question. Try this if it helps:

SELECT Productnr FROM Deliverable GROUP BY Productnr HAVING COUNT (Deliverernr)=1

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM