Help needed with MySQL query to join data spanning multiple tables with data used as column names

Posted by gurun8 on Stack Overflow See other posts from Stack Overflow or by gurun8
Published on 2010-06-10T21:21:55Z Indexed on 2010/06/11 2:32 UTC
Read the original article Hit count: 288

Filed under:
|

I need a little help putting together a SQL query that will give me the following resultsets:

alt text

and

alt text

The data model looks like this:

alt text

The tricky part for me is that the columns to the right of the "Product" in the resultset aren't really columns in the database but rather key/value pairs spanned across the data model.

Table data is as follows:

alt text

alt text

alt text

alt text

My apologies in advance for the image heavy question and the image quality. This just seemed like the easiest way to convey the information. It'll probably take someone less time to write the query statement to achieve the results than it did for me to assemble this question.

By the way, the "product_option" table image is truncated but it illustrated the general idea of the data structure.

The MySQL server version is 5.1.45.

© Stack Overflow or respective owner

Related posts about sql

Related posts about mysql