Performing Inner Join for Multiple Columns in the Same Table
- by frankiefrank
I have a scenario which I'm a bit stuck on. Let's say I have a survey about colors, and I have one table for the color data, and another for people's answers.
tbColors
color_code , color_name
1 , 'blue'
2 , 'green'
3 , 'yellow'
4 , 'red'
tbAnswers
answer_id , favorite_color , least_favorite_color , color_im_allergic_to
1 , 1 , 2 3
2 , 3 , 1 4
3 , 1 , 1 2
4 , 2 , 3 4
For display I want to write a SELECT that presents the answers table but using the color_name column from tbColors.
I understand the "most stupid" way to do it naming tbColors three times in the FROM section, using a different alias for each column to replace.
How would a non-stupid way look?