I have the following database schema:
Table: products
| id | name   | content |
|----|--------|---------|
| 1  | Pen    | ...     |
| 2  | Pencil | ...     |
| 3  | Rubber | ...     |
| 4  | Ruler  | ...     |
Table: feature_types
| id | name     |
|----|----------|
| 1  | Color    |
| 2  | Material |
| 3  | ...      |
| 4  | ...      |
Table: features
| id | product_id | feature_type_id | value     |
|----|------------|-----------------|-----------|
| 1  | 1          | 1               | Red       |
| 2  | 1          | 2               | Aluminum  |
| 3  | 2          | 1               | Green     |
| 4  | 2          | 2               | Wood      |
| 5  | 3          | 1               | White     |
| 6  | 4          | 2               | Plastic   |
My question is how can I do something like this:
SELECT *, ... FROM products ...
With result:
| id | name   | content | feature_type_1 | feature_type_2 |
|----|--------|---------|----------------|----------------|
| 1  | Pen    | ...     | Red            | Aluminum       |
| 2  | Pencil | ...     | Green          | Wood           |
| 3  | Rubber | ...     | White          | NULL           |
| 4  | Ruler  | ...     | NULL           | Plastic        |
So as you see, in results we have all columns from products table and additional columns for specified feature_types. Column names correspond to their identifiers, according to the pattern: "feature_type_{ID}".
I know feature_types IDs so it is not necessary to add all possible columns feature_types. I need only 2 additional columns with ID 1 and 2.