title: When do you give up set operations in SQL and go procedural?
body: <p>I was once given this task to do in an RDBMS:</p>
  
  <p>Given tables customer, order, orderlines and product. Everything done with the usual fields and relationships, with a comment memo field on the orderline table.</p>
  
  <p>For one customer retrieve a list of all products that customer has ever ordered with product name, year of first purchase, dates of three last purchases, comment of the latest order, sum of total income for that product-customer combination last 12 months.</p>
  
  <p>After a couple of days I gave up doing it as a Query and opted to just fetch every orderline for a customer, and every product and run through the data procedurally to build the required table clientside.</p>
  
  <p>I regard this a symptom of one or more of the following:</p>
  
  <ul>
  <li>I'm a lazy idiot and should have seen how to do it in SQL</li>
  <li>Set operations are not as expressive as procedural operations</li>
  <li>SQL is not as expressive as it should be</li>
  </ul>
  
  <p>Did I do the right thing? Did I have other options?</p>