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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T14:51:57+00:00 2026-06-12T14:51:57+00:00

I have an Answer database table below: Answer Table AnswerId SessionId QuestionId Answer 10

  • 0

I have an “Answer” database table below:

Answer Table

AnswerId SessionId QuestionId Answer
10       AAD       7          A
11       AAD       7          B
12       AAD       7          D
13       AAA       1          A
14       AAC       1          True

Now as you can see above there are 3 answers for question 7 in Exam (Session) AAD, there is 1 answer for question 1 in Exam (Session) AAA, and these is 1 answer for question 1 in Exam (Session) AAC.

So When I output the table in php/html, it should display it like this:

  Question  Answer

  7         ABD
  1         A
  1         True

But the problem is that it is displaying the table in 3 separate rows which I do not want:

Question  Answer
7         ABD
7         ABD
7         ABD
1         ATrue
1         ATrue

So I am guessing that I have got my GROUP BY CLAUSE incorrect, my question is that what should the GROUP BY Clause be so that it is correct?

 SELECT DISTINCT an.SessionId, an.QuestionId, q.QuestionContent, o.OptionType, q.NoofAnswers, GROUP_CONCAT( an.Answer
ORDER BY an.Answer
SEPARATOR  ' ' ) AS Answer, r.ReplyType, q.QuestionMarks
FROM Answer an
INNER JOIN Question q ON q.QuestionId = an.QuestionId
JOIN Reply r ON q.ReplyId = r.ReplyId
JOIN Option_Table o ON q.OptionId = o.OptionId
GROUP BY an.SessionId, an.QuestionId

Below I have included the SHOW CREATE TABLES for “Question” and “Answer” Tables:

Question Table:

 CREATE TABLE `Question` (
     `SessionId` varchar(10) NOT NULL,
     `QuestionId` int(10) NOT NULL,
     `QuestionContent` varchar(5000) NOT NULL,
     `NoofAnswers` int(2) NOT NULL,
     `ReplyId` int(1) NOT NULL,
     `QuestionMarks` int(4) NOT NULL,
     `OptionId` int(2) NOT NULL,
     PRIMARY KEY (`SessionId`,`QuestionId`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8

Answer Table:

CREATE TABLE `Answer` (
 `AnswerId` int(10) NOT NULL AUTO_INCREMENT,
 `SessionId` varchar(10) NOT NULL,
 `QuestionId` int(10) NOT NULL,
 `Answer` varchar(5) NOT NULL,
 PRIMARY KEY (`AnswerId`)
) ENGINE=InnoDB AUTO_INCREMENT=40 DEFAULT CHARSET=utf8

Below is the “Question” Table rows (I only include SessionId and QuestionId columns as they are relevant for this situation:

SessionId QuestionId 
AAA       1
AAC       1
AAD       7

The rows in the “Answer” table is at top of this question.

UPDATE: With the query above I get these results (Only including relevant columns):

SessionId  QuestionId  Answer
AAA        1           A A        // This row answer should only be "A"
AAC        1           True True  //This row answer should only be "True"
AAD        7           A B D      //This row is fine
  • 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-12T14:51:58+00:00Added an answer on June 12, 2026 at 2:51 pm

    You need to add GROUP BY clause. Try this, (it’s a simplified version)

    SELECT QuestionID, GROUP_CONCAT(Answer SEPARATOR '')
    FROM tableName
    GROUP BY SessionID, QuestionID
    

    SQLFiddle Demo

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

Sidebar

Related Questions

I have an Answer database table below: Answer Table AnswerId SessionId QuestionId Answer 13
I have an Answer database table below: Answer Table AnswerId SessionId QuestionId Answer 13
UPDATE: I found a solution. See my Answer below. My Question How can I
Now as you can see the query I have used above if a keyword
Problem solved: Thanks guys, see my answer below. I have a website running in
I have a dataset that returns questions and answers from the database, each answer
I have the following database table with information about people, diseases, and drugs: PERSON_T
i have table with name sample in my database it has threecolumns namely words,D1,D2
i have a gridview with search option by a database table.All working fine but
I have the following problem: in a database table are Sales recorded. One of

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.