Complex SQL Pivot
===

So I've got a query selecting data from 4 tables: 

 - cases
 - taxonomies (containing titles and data about taxonomies)
 - taxonomy_values (possible values for the taxonomies)
 - post_taxonomy_values (holds IDs from the case table, and IDs from the taxonomy table to link the two)

I'm attempting to select a row from the cases table and then get all taxonomy names and their values. Here's what I've got so far:

    select 
    cases.title, cases.content, cases.status, taxonomies.title as 'taxonomy', taxonomy_values.value as 'taxonomy_value'
    
    from cases, post_taxonomy_values, taxonomies, taxonomy_values 
    
    where 
    cases.slug = 'b-v-dpp' and
    post_taxonomy_values.post = cases.id and
    taxonomies.id = post_taxonomy_values.taxonomy and
    taxonomy_values.id = post_taxonomy_values.value

But this is what that generates:
![Current query result][1]

So basically what I'd like is to take the taxonomy names and make them column names, and set their values as part of the returned row.

Here's the structure of the tables:

**cases:**

![cases table][2]

**taxonomies:**

![taxonomies table][3]

**taxonomy_values** ('taxonomy' references an ID in the taxonomies table):

![taxonomy_values table][4]

**post_taxonomy_values** ('taxonomy' references an ID in the taxonomies table and 'value' references an ID in the taxonomy_values table):

![post_taxonomy_values table][5]

I've written and re-written this query but I just can't get my head round the problem, any help would be much appreciated!


  [1]: http://i.stack.imgur.com/H9HoA.png
  [2]: http://i.stack.imgur.com/uaTf2.png
  [3]: http://i.stack.imgur.com/v68lx.png
  [4]: http://i.stack.imgur.com/D9ffh.png
  [5]: http://i.stack.imgur.com/satJh.png