Performing Inner Join for Multiple Columns in the Same Table

Posted by frankiefrank on Stack Overflow See other posts from Stack Overflow or by frankiefrank
Published on 2010-05-09T16:27:09Z Indexed on 2010/05/09 16:38 UTC
Read the original article Hit count: 166

Filed under:
|
|
|
|

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?

© Stack Overflow or respective owner

Related posts about Oracle

Related posts about sql