Joining two tables (through a link), one which may yield multiple rows, together into one result.
- by Eikern
Lets say I've got a table listing car brands or models:
Cars:
Id | Brand
-----------
1 | BMW
2 | Audi
3 | Volvo
And I've also got another table which links features.
Link:
Id | carid | featureid
-----------------------
1 | 1 | 1
2 | 1 | 2
3 | 2 | 2
4 | 3 | 1
5 | 3 | 2
6 | 3 | 3
And I've got the table listing the features.
Features:
Id | Feature
-----------
1 | A/C
2 | 4WD
3 | Heated seats
I want to list these results on my front page like this:
BMW
A/C
4WD
Audi
4WD
Volvo
A/C
4WD
Heated seats
What's the best/most efficient way of doing this (using PHP and MySQL)?