title: Generating all possible combinations of a timetable using an SQL Query
body: <p>I have an awkward SQL Puzzle that has bested me. </p>
  
  <p>I am trying to generate a list of possible configurations of student blocks so I can fit their course choices into a timetable. A list of possible qualifications and blocks for a student could be as the following:</p>
  
  <pre><code>Biology A
  Biology C 
  Biology D 
  Biology E 
  
  Chemistry B 
  Chemistry C 
  Chemistry D 
  Chemistry E 
  Chemistry F 
  
  Computing D
  Computing F 
  
  Tutorial A 
  Tutorial B 
  Tutorial E 
  </code></pre>
  
  <p>A possible solution of blocks for a student could be</p>
  
  <pre><code>Biology D
  Chemistry C 
  Computing F 
  Tutorial E 
  </code></pre>
  
  <p>How would I query the above dataset to produce all possible combinations of lessons and blocks for a student? I could then pare down the list removing the ones that clash and choose one that works. I estimate that in this instance there will be about 120 combinations in total.</p>
  
  <p>I could imagine that it would be some kind of cross join. I have tried all sorts of solutions using window functions and cross apply etc but they have all had some kind of flaw. They all tend to get tripped up because each student has a different number of courses and each course has a different number of blocks.</p>
  
  <p>Cheers for any help you can offer! I can paste in the gnarled mess of a query I have if necessary too!</p>
  
  <p>Alex</p>