title: Advanced grouping of items in Oracle SQL
body: <p>I have an interesting problem. I have to assign an ID to a group of orders, based on whether they are packed in the same group of containers or not. One order may be in one or many containers, which means that not all containers in the group contain all the orders. For example, given these orders:</p>
  
  <pre><code> ORDER1 is in container A and B
   ORDER2 is in container B and C
   ORDER3 is in container C and D
   ORDER4 is in container E
  </code></pre>
  
  <p>There should be two groups, the first containing ORDER1, ORDER2 and ORDER3, and the second containing only ORDER4. Notice that ORDER1 and ORDER3 do not share any containers.</p>
  
  <p>I can think of a reasonably straightforward procedural algorithm for doing this grouping - getting the details right might be a bit painful though.</p>
  
  <p>However, I like to have an SQL based solution if possible, but it's beyond my grasp. I am using Oracle 10.2 - I am guessing that some funky features might come in to play here.</p>