Hi all,
I have a database which has two tables Places and Attributes.
Attributes contains information about the place, such as number of bedrooms and number of floors, but only has two fields - attribute type and value.
This means that when I query the two tables, I get the following returned:
PlaceRef | Address | AttributeType | Value
---------------------------------------------
ANY123 | 123 Any St | FLOORS | 2
ANY123 | 123 Any St | BEDS | 3
ANY123 | 123 Any St | BATHS | 2
ANY506 | 506 Any St | FLOORS | 2
ANY506 | 506 Any St | BEDS | 2
I need to normalize this so I get:
PlaceRef | Address | Floors | Beds | Baths
---------------------------------------------
ANY123 | 123 Any St | 2 | 3 | 2
ANY506 | 506 Any St | 2 | 2 |
I could do this with sub selects, taking the value where the Attribute Type = 'xxx' but this would mean that I need to know each of the Attribute Types.
It would be better if I could build this dynamically so that if any Attributes are added or taken away then it automatically picks this up.
I was thinking of using a loop but not sure how I would achieve this?
Can anyone help?
Thanks,
I have a database which has two tables Places and Attributes.
Attributes contains information about the place, such as number of bedrooms and number of floors, but only has two fields - attribute type and value.
This means that when I query the two tables, I get the following returned:
PlaceRef | Address | AttributeType | Value
---------------------------------------------
ANY123 | 123 Any St | FLOORS | 2
ANY123 | 123 Any St | BEDS | 3
ANY123 | 123 Any St | BATHS | 2
ANY506 | 506 Any St | FLOORS | 2
ANY506 | 506 Any St | BEDS | 2
I need to normalize this so I get:
PlaceRef | Address | Floors | Beds | Baths
---------------------------------------------
ANY123 | 123 Any St | 2 | 3 | 2
ANY506 | 506 Any St | 2 | 2 |
I could do this with sub selects, taking the value where the Attribute Type = 'xxx' but this would mean that I need to know each of the Attribute Types.
It would be better if I could build this dynamically so that if any Attributes are added or taken away then it automatically picks this up.
I was thinking of using a loop but not sure how I would achieve this?
Can anyone help?
Thanks,