Skip to content
Advertisement

min and count without limit

I need to select a receipt with 3 conditions:

  1. total receipt > 50 (receipt.total)
  2. associated purchases doesn’t include item “cucumbers” (product.pname)
  3. the number of suppliers (product.sid) of associated products is the lowest

I have the following tables set up:

sample data:

So far I have the following but it is not getting the receipt with the lowest number of sid:

I’m not allowed to use order by and limit. What am I doing wrong?

Advertisement

Answer

Without ORDER BY:

Simplifying the NOT EXISTS logic:

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement