I have three tables. Foo, Attrib, FooAttrib. Where FooAttrib is the bridge between foo and attrib. As you can see there are many foo’s and many attribs in the table.
Foo FooAttri Attrib
------------ ----------------------------- --------------
| id | Name | | fooId | attribId | value | | id | Descrip |
|----|-------| |---------|-----------|-------| |----|---------|
| 1 | Sam | | 1 | 1 | red | | 1 | Color |
| 2 | Bill | | 1 | 2 | Grape | | 2 | Flavor |
| 3 | Ted | | 2 | 1 | Blue | | 3 | Weight |
------------ | 3 | 3 | 10 | --------------
| 1 | 3 | 5 |
| 2 | 3 | 1 |
-----------------------------
I know how to get the following:
fooId Name Attrib Value
1 Sam Color red
1 Sam Flavor Grape
1 Sam Weight 5
2 Bill Color Blue
2 Bill Weight 1
3 Ted Weight 10
But what I want to know is; Is it possible to build a select statement so that I get foo and attrib data all returned in one result set that looks like the following?
fooId Name Color Flavor Weight
1 Sam red Grape 5
2 Bill Blue 1
3 Ted 10
You could do it if you know the total possible arguments you want at select time: