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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T01:54:49+00:00 2026-06-10T01:54:49+00:00

I’m totally new to SQL so I guess my question is quite simple but

  • 0

I’m totally new to SQL so I guess my question is quite simple but I wasn’t able so far to peform the desired output by myself.

I did a survey and asked 3 people to solve assignment A (with 3 tasks) and 3 people to solve assignment B (with 3 tasks).

And then I made a table which looks like this:

Table: Results
+---------+---------+---------+---------+---------+
| ID      | AssgnID | Answer1 | Answer2 | Answer3 |
+---------+---------+---------+---------+---------+
| 1       | A1      | 20      | 45      | 80      |   
| 2       | A1      | 22      | 40      | 82      |  
| 3       | A1      | 25      | 39      | 85      |
| 4       | A2      | 45      | 10      | 75      |
| 5       | A2      | 50      | 15      | 72      |
| 6       | A2      | 50      | 12      | 80      |
+---------+---------+---------+---------+---------+

What I now want to do is, to show for AssgnID A1 and A2 all the Answers in one row like this:

Table: Results per AssgnID
+---------+---------+---------+---------+---------+--------+---------+---------+--------+---------+---------+
| ID      | AssgnID | Answer1 | Answer2 | Answer3 |Answer4 | Answer5 | Answer6 |Answer7 | Answer8 | Answer9 |
+---------+---------+---------+---------+---------+---------+---------+---------+-------+---------+---------+
| 1       | A1      | 20      | 45      | 80      | 22     | 40      | 82      | 22     | 40      | 82          
| 2       | A2      | 45      | 10      | 75      | 50     | 15      | 72      | 50     | 12      | 80                  
+---------+---------+---------+---------+---------+---------+---------+---------+-------+---------+---------+

I’m able to show the distinct AssgnID by using DISTINCT or GROUP BY but I can’t show all the results in the same output.

Do I have to try something with a JOIN?

I appreciate your help a lot. 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-10T01:54:50+00:00Added an answer on June 10, 2026 at 1:54 am

    If you are willing to accept your list of answers as a comma-separated list rather than actual columns, you can use PostgreSQL’s string_agg() to force them into a list by concatenating the three answer columns from each row into a unit, then grouping all of those together:

    SELECT 
      AssgnID,
      /* Concat the 3 answers together with `,`, the group all rows together separated by `,` */
      string_agg((Answer1 || ',' || Answer2 || ',' || Answer3), ',') AS Answers
    FROM yourtable
    GROUP BY AssgnID
    

    Would produce:

    A1   20,45,80,22,40,82,22,42,82
    A2   45,10,75,50,15,72,50,12,80
    

    If you need to perform additional SQL operations, however, the best course of action and best permanent solution is to redesign your table structure to store these answers in a normalized way. This method defines the survey in one table, and another table holds one row per answer, or three rows per SurveyID.

    Table Surveys

    SurveyID
    AssgnID
    UserID
    

    Table Answers

    SurveyID
    Answer
    Value
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This could be a duplicate question, but I have no idea what search terms
Seemingly simple, but I cannot find anything relevant on the web. What is the
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this

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.