1

I've got three tables. Product, Warehouse and IsIn.

Product:

  • productID
  • name
  • price

Warehouse:

  • warehousID
  • name

IsIn:

  • productID*
  • warehousID*
  • quantity

I now want to write a question where i get all warehouses where a specific product does not exist.

I can get a table where the specific product are, but when i try to get where it's not, I get the wrong answer.

Does anyone know how i can write the question?

Shadow
  • 33,525
  • 10
  • 51
  • 64
joey
  • 13
  • 3
  • 1
    So exactly what was your attempt? Edit question to show. – June7 Mar 07 '21 at 22:34
  • Does this answer your question? [Find records from one table which don't exist in another](https://stackoverflow.com/questions/367863/find-records-from-one-table-which-dont-exist-in-another) – June7 Mar 07 '21 at 22:34

1 Answers1

0

I now want to write a question where i get all warehouses where a specific product does not exist.

This sounds like a NOT EXISTS query:

select w.*
from warehouse w
where not exists (select 1
                  from isin i
                  where i.warehouseid = w.warehouseid and
                        i.productid = ?
                 );

You may want to add and i.quantity > 0 in the subquery. It is not clear if quantity is important for the question.

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786