I’m trying to do a validation using an Oracle SQL query, and the idea is:
There are items, and to every item there could be more than one suppliers.
I have a set of items (in a shopping bag) and want to verify if there is at least one common supplier between them. That means that all the items in the bag share at least one supplier.
Simplifying, the tables are:
BAG table with bag_id and item columns.
SUPPLY table with item and supplier columns.
Thank you!
This should give you a list of suppliers that match more than one item, with the most common suppliers on top
If you need to find suppliers that match ALL items in the bag, then use this query:
You can check if the list is empty to determine if no common suppliers exist by wrapping this with an
EXISTSstatement.