How to Search a Database of Package Deals for Specific Items with the Fewest Unwanted Extra Items Short Description

I have a database of special offers that bundle several items together.  I want to be able to search for a list of specific items and get a combination of bundles that includes all those items with the fewest unwanted extras.

Example

My database has bundles like these:


Bundle 1: Item A X2, Item B X1, Item D X4
Bundle 2: Item A X5, Item C X1, Item E X3
Bundle 3: Item B X2, Item C X3, Item D X3
Bundle 4: Item C X10, Item D X1, Item F X4


I want 10 of Item A, 4 of Item C, and 1 of Item E.  I want to search for a combination of bundles that yields the items I want with the fewest extra items.  The items I want can vary and should be easily editable in the search.
I don't think anyone has come up with a complete answer for your question. This sounds like a complex math question which does not belong on the "Database Administrators" site.

With that said, Joe Celko has an article that might help you. Bin Packing Problems: The SQL