I have this two tables:
Main:
id | name | hair_color | eye_color
1 | a | 1 | 2
2 | b | 1 | 3
3 | c | 4 | 3
Items:
id | name
1 | black
2 | blue
3 | green
4 | blonde
I want to select one row from the Main table but replace the hair_color and eye_color ids by theirs name that fits by the Items table.
I mean, for row number 1 in Main table, I want to get this details:
$res = array(
id=>1,
name=>'a',
hair_color=>'black',
eye_color=>'blue');
I tried this incorrect mysql query:
SELECT `main`.`id`, `main`.`name`, `items`.`name` as `hair_color`, `items`.`name` as `eye_color`
FROM `main`
LEFT JOIN `items` ON `main`.`hair_color` = `items`.`id
LEFT JOIN `items` ON `main`.`eye_color` = `items`.`id
WHERE `main`.`id` = 1
I know that this query is incorrect, but I don't know how to do this right.
Any idea?
Thanks
EDIT:
Thanks all!