title: get grouped results with sparql query
body: <p>I still feel like a SPARQL newbie, so I may be way off base about what SPARQL GROUP BY does, but here's my questions. </p>
  
  <p>Suppose I wanted to request all resources in graph database called Categories, and I wanted to get all the items associated with these categories, along with the names of the items and their price. </p>
  
  <p>Right now my SPARQL queries are giving me back something like the following table:</p>
  
  <pre><code>**Categories Item ItemName ItemPrice**
  Tools HammerID Hammer $12
  Tools SawID Saw $13
  Tools WrenchID Wrench $10
  Food AppleID Apple $5
  Food CornID Corn $1
  </code></pre>
  
  <p>I wanted to use GROUP BY to group the items under a single category, so that when I start processing it, I can look through each unique category and then display the items that belong in that category. </p>
  
  <p>Right now if I loop through the above results, I will be iterating over 5 entries instead of 2.</p>
  
  <p>The other way I can describe the results I want are by imaging what the corresponding json data would look like. I want something like:</p>
  
  <pre><code> [
    tools: [
           {id: hammerId
            title: hammer
            price: $12},
           {id: sawId
            title: saw
            price: $13},
           {id: wrenchId
            title: wrench
            price: $10}
        ],
     food: [
           {id: appleId
            title: apple
            price: $5},
           {id: cornId
            title: corn
            price: $1}
           ]
      ]
  </code></pre>
  
  <p>With the results, like this I can directly loop over the top level items, and then display the results for each. </p>
  
  <p>Can I use GROUP BY to tell SPARQL to give me results like this? </p>