I'm fairly new with the mysql and database stuff so go easy on me I've been scanning web tutorial to try to find some example similar to this, but haven't had much luck. Anyway, I'm trying to do a sql query that will join several tables together.
Here's an example of the tables I have:
What I want to do is to join them together so I can say pull a row from Table1, but it will replace the Type # with the corresponding Type Name and each bonus # with the corresponding Bonus name.
So if I pulled line 1 the end results would be
I can get so far as getting say Abba and Test to show up with something similar to this:
SELECT main.name type.name FROM main LEFT JOIN type ON (main.type = type.ID)
However I don't know how to go further than this. I especially don't understand how to do bonus1, bonus2 and bonus3 because they are each pulling from the same table just three times.
Thanks,
Jason
Here's an example of the tables I have:
Code:
Table 1 (Main Table)
| Name | Type | Bonus1 | Bonus2 | Bonus3 |
------------------------------------------
| Abba | 1 | 2 | 1 | 3 |
| Baba | 2 | 3 | 2 | 1 |
Table 2 (Type Table)
| ID | Name |
-----------------
| 1 | Test |
| 2 | Example |
Table 3 (Bonus Table)
| ID | Name |
----------------
| 1 | Bronze |
| 2 | Silver |
| 3 | Gold |
So if I pulled line 1 the end results would be
Code:
| Name | Type | Bonus1 | Bonus2 | Bonus3 |
------------------------------------------
| Abba | Test | Silver | Bronze | Gold |
SELECT main.name type.name FROM main LEFT JOIN type ON (main.type = type.ID)
However I don't know how to go further than this. I especially don't understand how to do bonus1, bonus2 and bonus3 because they are each pulling from the same table just three times.
Thanks,
Jason