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 7805529
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T02:15:32+00:00 2026-06-02T02:15:32+00:00

brief overview so this is in context, I have an application in java that

  • 0

brief overview so this is in context, I have an application in java that uses SQL as the database in the application users have to select 8 countries as answers to a question (these countries may be picked more than once, eg. Australia could be their answer for Q1 and Q3)

the country ID is then saved into their answers table alongside their user_id

i am trying to write a query that will get all of the country names that they chose as their answers, (i will then set the text of 8 labels in my java application so the user can see the 8 countries they selected as their answers)

i have no problem with SQL joins etc, the query i have written does pull the correct information however if someone has answered multiple question with the same answer(country) then it only returns the country names that were answers (so basically i want 8 returned but if the same country was selected twice it returns only 7) the issue with this is that different users could have answers different questions with the same country so i cannot simply use the answers returned and set 2 labels with the value from one of returned rows in the query (i hope that makes sense)

here is my SQL

SELECT C.C_NAME
FROM COUNTRY C INNER JOIN
TBL_ANSWERS T ON 
T.ANSWER1_ID = C.C_ID 
OR
T.ANSWER2_ID = C.C_ID 
OR
T.ANSWER3_ID = C.C_ID 
OR
T.ANSWER4_ID = C.C_ID 
OR
T.ANSWER5_ID = C.C_ID 
OR
T.ANSWER6_ID = C.C_ID 
OR
T.ANSWER7_ID = C.C_ID 
OR
T.ANSWER8_ID = C.C_ID
WHERE T.USER_ID = '4' 

Im sure there is probably something rather easy i have missed out but any help would be much appriciated

also sorry if my question didnt fully make sense ill be happy to answer any questions you might have

thanks

  • 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-02T02:15:33+00:00Added an answer on June 2, 2026 at 2:15 am

    It seems like you just want something like this:

    SELECT C_NAME, AnswerNum
    FROM
    (
    SELECT C.C_NAME, "1" AS AnswerNum, T.USER_ID
    FROM COUNTRY C 
        JOIN TBL_ANSWERS T 
            ON  T.ANSWER1_ID = C.C_ID 
    UNION ALL
    SELECT C.C_NAME, "2" AS AnswerNum, T.USER_ID
    FROM COUNTRY C 
        JOIN TBL_ANSWERS T 
            ON  T.ANSWER2_ID = C.C_ID 
    ...
    UNION ALL
    SELECT C.C_NAME, "8" AS AnswerNum, T.USER_ID
    FROM COUNTRY C 
        JOIN TBL_ANSWERS T 
            ON  T.ANSWER8_ID = C.C_ID 
    ) AS AnswersJoined
    WHERE USER_ID = '4' 
    

    However, I would seriously consider reworking your tables so that you use relationship mapping tables to figure out the questions and answers. This would allow this to be more easily created in one query

    Something like

    Tbl_Answer

     Question_Id|User_Id|Response_Id
    

    Tbl_Question

     Id|QuestionNumber
    

    This would allow you to just run a simple BETWEEN. Something like this:

    SELECT C.Name
    FROM Country C
    WHERE EXISTS
    (
        SELECT 1 
        FROM Tbl_Answer T
            JOIN Tbl_Question Q
                ON Q.Id = T.Question_Id
        WHERE T.User_Id = 4 AND T.Response_Id = C.C_ID
            AND Q.QuestionNumber BETWEEN 1 AND 8
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working with a SQL database for a Skills Matrix application and I need
Semi-brief overview... --- Indices is a Python list of indices that correspond to the
Brief Description: I have a table that stores articles. Articles are listed on table
Brief Idea about the flow : I have say minimum 1 and maximum 18
Brief intro about my requirement. I have an empty JSF dataTable. Now, when I
I'll keep this brief. I am trying to keep a map between strings and
I've this brief snippet: String target = baseFolder.toString() + entryName; target = target.substring(0, target.length()
Brief: Based on a query, I have multiple checkboxes generated dynamically. The value of
Brief summary: I need a script/plugin for Firefox that selects the load next 25
I have a php page that creates page data from two .txt files (one

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.