Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 787873
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T21:16:25+00:00 2026-05-14T21:16:25+00:00

I have a scenario which I’m a bit stuck on. Let’s say I have

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T21:16:25+00:00Added an answer on May 14, 2026 at 9:16 pm

    This seems like the way to go:

    SELECT
      A.answer_id
      ,C1.color_name AS favorite_color_name
      ,C2.color_name AS least_favorite_color_name
      ,C3.color_name AS color_im_allergic_to_name
    FROM tbAnswers AS A
    INNER JOIN tbColors AS C1
      ON A.favorite_color = C1.color_code
    INNER JOIN tbColors AS C2
      ON A.least_favorite_color = C2.color_code
    INNER JOIN tbColors AS C3
      ON A.color_im_allergic_to = C3.color_code
    

    Rather than “stupid”, I’d venture that this is a pretty standard query. This also presumes that all columns will have a valid value. Otherwise, replace all INNER JOINs with LEFT JOINs

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

we have this scenario: A server which contains needed data and client component which
I have a scenario which is causing strange behavior with WPF data binding and
I have one scenario in which the user can define the column and that
I have a scenario in a system which I've tried to simplify as best
I have a scenario. (Windows Forms, C#, .NET) There is a main form which
The scenario is this We have two applications A and B, both which are
I have a scenario where I need to upload a file from one web
I have this scenario where I need data integrity in the physical database. For
I have a scenario which is not easy to explain, but I am sure
We have a scenario in which we like to detect when the user has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.