Skip to content
Advertisement

If there is data linked to an order number, how do i pull some but not the other (not exists?)?

I’m using Toad for Oracle.

I currently have Order Numbers with items in both our yard and our warehouse. I’m looking to see items that ONLY have items in the yard.

Essentially I need a count of the different items in the yard and a sum of their weight for each order

I currently have it where it’s counting the items for each order that are in the yard but it’s not limiting it to orders that ONLY have yard items

From the above sample set, I would only want to see Order1 because it is the only order that contains ONLY items located in the Yard

Advertisement

Answer

I am using your two sample tables (table 1 = orders, table 2 = items). This is how to find the order numbers of orders that contain yard items but no warehouse itms:

If you want to show complete orders, use above query in a subquery, e.g.:

If you want an aggregation per order instead, you can modify the query accordingly, e.g.:

And if you want an aggregation per item, you might need the subquery plus a separate aggregation.

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