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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T23:47:10+00:00 2026-05-20T23:47:10+00:00

I have two tables question and answers. – questions{id,user_id,question,date} – answers {id,q_id,user_id,answer, date} I

  • 0

I have two tables question and answers.

- questions{id,user_id,question,date}
- answers {id,q_id,user_id,answer, date}

I want to retrieve the questions and answers that have been inputted by the same user

 i.e. select all answer and all questions for ID=39 order by date DESC

and also after I have a query, and I’m wanting to while through the fetch array, and displaying the data, how can I distinguish whether it was a question or an answer, so I can display them correctly.

EDIT:

SELECT 'Q' AS
TYPE , q.question AS value, q.date
FROM questions q
WHERE q.user_id =39
UNION ALL SELECT 'A' AS
TYPE , q.question AS value, a.date
FROM answers a,questions q
WHERE a.q_id = q.id
AND
WHERE a.user_id =39
ORDER BY `date` DESC

im sorry but im trying to get the question that has been answered rather then the answer itself. i updated the sql and the database design on top, but i keep getting an error

  • 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-20T23:47:10+00:00Added an answer on May 20, 2026 at 11:47 pm

    Use:

      SELECT 'Q' AS type,
             q.question AS value,
             q.date
        FROM QUESTION q
       WHERE q.user_id = ?
    UNION ALL
      SELECT 'A' AS type,
             a.answer AS value,
             a.date
        FROM ANSWER a
       WHERE a.user_id = ?
    ORDER BY `date` DESC
    

    UNION and UNION ALL are used to combine queries to return a single result set. UNION removes duplicates; UNION ALL does not remove duplicates and is faster than UNION because of this. But there needs to be the same number of columns in the SELECT clauses of all the SELECT statements in a UNION’d statement. And their data types have to match at each position.

    To differentiate between answers and question values, the example defined static values “A” to stand for answers, and “Q” to stand for questions. Your application layer code can work off these to format the data as desired.

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

Sidebar

Related Questions

i have four tables user-question contains two columns: questionID, userID, the questions that the
I am having two tables question_bank(ques_id,question,answer,a,b,c,d) random_question_bank(user_id,q1,q2,............,q20) I have filled the user_id from users.
I have a question: I have two MSSQL tables, items and states, that are
Ok, so say I have two tables. Question questionID QuestionDescription Answer AnswerID QuestionID AnswerDescription
I have two tables, one that contains questions (that are considered 'templates'): |QuestionID|QuestionText |
I have two tables: answers{..., question_id} and questions{..., answer_id} . In the models I
I have two tables, questions and answers . answers contains a key *question_id* When
I have two tables questions and answered . answered contains the answers for all
I have two tables ( questions and answers ), and wish to select the
I have problem with one-to-many mapping. Two tables questions(PK(id), text) and answers(PK(id, questionId), text)

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.