mardi 7 avril 2015

Merging two vertical tables onto one horizontal table


Vote count:

0




Table Definitions


Table 1 (horizontal) This is a table of users



| id | name | phone |
---------------------
| 1 | Bob | 800 |
| 2 | Phil | 800 |


Table 2 (Vertical Table) This is a table of teams



| id | name |
------------------
| 1 | Donkey |
| 2 | Cat |


Table 3 (Vertical Table) This table is connecting the first two



| id | user_id | team_id |
--------------------------
| 1 | 1 | 1 |
| 2 | 1 | 2 |
| 3 | 2 | 1 |




My Goal


I would like to be able to query the data in such a way that i get the following back:



| id | name | phone | Donkey | Cat |
-------------------------------------
| 1 | Bob | 800 | 1 | 1 |
| 2 | Phil | 800 | 1 | Null |


This table would have my horizontal table data, then a combination of the other two vertical tables to create the appended columns. Where table 2 ends up being the column name headings. And the row valus are pulled from table three as a boolean.



asked 34 secs ago







Merging two vertical tables onto one horizontal table

Aucun commentaire:

Enregistrer un commentaire