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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T20:11:56+00:00 2026-05-28T20:11:56+00:00

Given this output to one query: ID | Question | Answer 1 | 1

  • 0

Given this output to one query:

ID   |  Question  |  Answer

1    |     1      |    2
1    |     2      |    5
1    |     3      |    5
2    |     1      |    2
2    |     2      |    2
3    |     4      |    7

Is there any way in sql to have something like:

ID   |  Question  |  Answer
1   
     |     1      |    2
     |     2      |    5
     |     3      |    5
2    
     |     1      |    2
     |     2      |    2
3    
     |     4      |    7 

The objective is to not repeat ID over and over, but i have nothing to group by for as i want to show all results individually.

I have tried working around GROUP BY but without much results so far.
I’m using SQL Server.

  • 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-28T20:11:57+00:00Added an answer on May 28, 2026 at 8:11 pm

    You need to

    • insert extra rows for headings
    • remove the ID from the detail row
    • make sure the order is correct, so the right headings are over the right details.

    Example:

    select
        -- Show the ID only if it is not a detail row
        case when Question is null then ID else null end as ID,
        Question, 
        Answer
    From 
    (
        -- Detail rows
        select ID, Question, Answer from T1
        union all
        -- Heading rows
        select distinct ID, cast(null as type) as Question, cast(null as type) as Answer from T1
    
    )x
    order by 
        -- In order of ID
        x.ID, 
        -- but make heading rows come first
        case when x.Question is null then 0 else 1 end asc, 
        -- then order by question
        x.Question
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this is probably a very stupid question; in a bash script, given the output
I'm trying something like this Output.py print Hello Input.py greeting = raw_input(Give me the
I have table called Direccion other called Cliente each one defined like this public
I have a query similar to this: SELECT itemID FROM itemTable WHERE itemID LIKE
Suppose there is a System A which gives some output. This output is used
There was a previous question on StackOverflow about this subject (can insert the link,
I have a cross reference table that looks like this: id document_id subject_id 1
I have the following output in a query. SKILL LEVEL SCORERANGE ----------------------------------------------------------------------------- Stunts LOW
Say I have a table like this: x1 | y1 | x2 | y2
I am having one query given below in that Employee , ShiftAllocation , ShiftMaster

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.