I have a single table of key value pairs for multiple components. Each type of component can have different attributes (keys), although each type will always have the same attributes.
For example:
-----------------------------------
| Comp_ID | KeyField | ValueField |
-----------------------------------
| A | Size | Big |
| A | Weight | 10 |
| A | Colour | Green |
| B | Length | Short |
| B | Density | 1.5 |
| B | Colour | Yellow |
| B | Radius | 3 |
| C | Size | Small |
| C | Weight | 20 |
| C | Colour | Red |
| D | Size | Small |
| D | Weight | 20 |
| D | Colour | Blue |
A, C and D are all the same type of component while B is different.
How can I do the following:
- Select only the components with a certain attribute (key). Eg: only components with the size key.
- Display this with one row per component ID.
Based on the above example I would expect a table like this:
-------------------------------------
| Comp_ID | Size | Weight | Colour |
-------------------------------------
| A | Big | 10 | Green |
| C | Small | 20 | Red |
| D | Small | 20 | Blue |
I am querying an oracle database if that matters but hopefully answers will be generic SQL - the simpler the better:)
Edit: I realise this is not the best way to store the data but this is beyond my control - This is a vendor solution from GE and (obviously) can't be changed. I Just need to query the data.