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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T01:27:19+00:00 2026-06-14T01:27:19+00:00

I need some help in the query I have where I don’t know if

  • 0

I need some help in the query I have where I don’t know if I am including the Correct GROUP BY Clause and selecting the fields from the right tables in the SELECT clause:

Below is the database Tables:

Session Table

SessionId  SessionName
1          AAA
2          AAB

Question Table

SessionId  QuestionId  QuestionContent            QuestionMarks
1          1           What is 2+2?               2
1          2           What is 4+4?               3
2          1           What is 10+10 and 11+11?   5
2          2           What is 15+15?             5
2          3           What is 20+20 and 40+40?   7

Answer Table

AnswerId SessionId  QuestionId Answer
1        1          1          B
2        1          2          C
3        2          1          A
4        2          1          D
5        2          2          A
6        2          3          D
7        2          3          E

Below is the query:

   $query = "SELECT q.SessionId, s.SessionName, q.QuestionId, q.QuestionContent, GROUP_CONCAT(DISTINCT Answer SEPARATOR '') AS Answer, q.QuestionMarks 
   FROM Session s 
   INNER JOIN Question q ON s.SessionId = q.SessionId
   JOIN Answer an ON q.QuestionId = an.QuestionId
   WHERE SessionName = "AAB"
   GROUP BY an.SessionId, an.QuestionId
   ";

I want to display each question which belongs to session “AAB”. So it should display QuestionId, QuestionContent, Answer and QuestionMarks like below:

 QuestionId  QuestionContent              Answer  QuestionMarks
    1           What is 10+10 and 11+11?     AD       5
    2           What is 15+15                A        5
    3           What is 20 + 20 and 40+40?   DE       7

At the moment if I am search for lets say questions in Session “AAB”, it is displaying this below:

QuestionId  QuestionContent              Answer  QuestionMarks
    1           What is 10+10 and 11+11?     AD       5
    2           What is 15+15                A        5
    3           What is 20 + 20 and 40+40?   DE       7
    1           What is 10+10 and 11+11?     AD       5
    2           What is 15+15                A        5
    3           What is 20 + 20 and 40+40?   DE       7
    1           What is 10+10 and 11+11?     AD       5
    2           What is 15+15                A        5
    3           What is 20 + 20 and 40+40?   DE       7
    1           What is 10+10 and 11+11?     AD       5
    2           What is 15+15                A        5
    3           What is 20 + 20 and 40+40?   DE       7
    1           What is 10+10 and 11+11?     AD       5
    2           What is 15+15                A        5
    3           What is 20 + 20 and 40+40?   DE       7
  • 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-14T01:27:21+00:00Added an answer on June 14, 2026 at 1:27 am

    Your answer table has a session ID in it that it looks like you missed in your join. Also you shouldn’t need the DISTINCT in your group_concat, unless your storage of the same answer for the same question/session multiple times is accidental, in which case I would solve that accident instead of coding a work around into the query.

    SELECT q.SessionId, s.SessionName, q.QuestionId, q.QuestionContent, GROUP_CONCAT(DISTINCT Answer SEPARATOR '') AS Answer, q.QuestionMarks 
    FROM Session s 
    INNER JOIN Question q ON s.SessionId = q.SessionId
    JOIN Answer an ON q.QuestionId = an.QuestionId
                 AND an.sessionID = s.sessionID
    WHERE SessionName = "AAB"
    GROUP BY an.SessionId, an.QuestionId
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Need some help with a query.. I have three tables. Source id name 1
I need some help with a LINQ query in VB.Net, please. I have this
Need some help with putting this query together. I'm using Mysql I have two
I don't have a specific query here ; just need some design guidelines. I
i have one query that need some changes, and i don't get any clue
I need some help a query. For each movie in my database that has
I am new to SQL Server 2008, and I need some help in query
I need some help with SQL Query. I am trying to select all records
I'm working on a web application and need some help with a query. I'm
I need some help putting together this query in Django. I've simplified the example

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.