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

  • SEARCH
  • Home
  • 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 8459777
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T13:25:21+00:00 2026-06-10T13:25:21+00:00

I tried to work out around this. But I think I am getting no

  • 0

I tried to work out around this. But I think I am getting no where.

I have 3 tables:

This tale contains all questions and question types:

    Table: Ref
    id    |    type   |   info
    ==========================
    1          SS         Education
    ---------------------------
    2          RB         Gender
    ---------------------------
    3          ST         State

This table contains “options” for the questions in the above table ‘Ref`

    Table: ref_ans
    id    |  q_id   |   answer_text
    ===========================
    1          1        Masters     
    ---------------------------
    2          1        Bachelors     
    ---------------------------
    3          1        Undergrad
    ---------------------------
    4          2        Male     
    ---------------------------
    5          2        Female
    ---------------------------
    6          2        Dont want to disclose

This table contains states (type =”ST” in table Ref)

    Table: us_states

    id    |  answer_text 
    ===========================
    1        Alaska     
    ---------------------------
    2        Alabama     
    ---------------------------
    3        Arkansan
    ---------------------------
    4        Arizona     
    ---------------------------
    5        Baltimore
    ---------------------------
    etc

The result I want is:

    ref.id, ref_ans.id, ref.answer_text / us_states.answer_text

*for a given ref.question_id *.

And the condition is: If the question_id, for which the answers requested is ‘ST’, it should pull the answers from us_states, otherwise, it should pull from ref-ans table.

I tried this. Obviously, this did not work:

    SELECT ref.id, 
         CASE WHEN ref.type = 'ST' THEN 
             (SELECT ID, answer_text FROM us_states )
         ELSE 
             (SELECT id, answer_text FROM ref_ans)  
    END

    FROM ref
   WHERE ref.ID = <id>

Any ideas?

  • 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-06-10T13:25:22+00:00Added an answer on June 10, 2026 at 1:25 pm

    Try:

    SELECT    a.id, 
              COALESCE(b.id, c.id) AS ans_id,
              COALESCE(b.answer_text, c.answer_text) AS answer_text
    FROM      ref a
    LEFT JOIN ref_ans b ON a.id = b.q_id
    LEFT JOIN us_states c ON a.type = 'ST'
    WHERE     a.id = <id> AND (
                  (a.type <> 'ST' AND b.id IS NOT NULL) OR
                  (a.type =  'ST' AND c.id IS NOT NULL)
              )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have tried many things, but I'm still not getting this to work. Here's
I have been reading other questions and answers around this but I am not
I can't figure out why this won't work, I've tried it 100 ways. The
I tried this JavaScript but it doesn't work - here I need to change
Hey all, I think this might be a bug, but it's killing me. I
I know a similar question has been posted before but I think this is
Sorry for the long question, but I have been stuck on this for days
I just finished writing this script and getting it to work but I need
I recently tried to pull some results and was struggling to work out the
When it comes to web development I have always tried to work SMART not

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.