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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T02:48:16+00:00 2026-06-16T02:48:16+00:00

Is it possible to transpose a table with repeated columns? Existing table: user_id question_id

  • 0

Is it possible to transpose a table with repeated columns?

Existing table:

user_id    question_id   body 
1          1             'Text1 1'
1          1             'Text1 1-2'
1          2             'Text1 2'
1          3             'Text1 3'
2          1             'Text2 1'
2          2             'Text2 2'

Cross tab or solution based on

MAX(CASE WHEN r.question_id = 1 THEN r.body ELSE NULL END) AS 'question1'

is not applicable in this scenario because always is match last occurance of repeated attribute.

I want to perform search on the question body but I don’t know how without a transposed table.
E.g. I want to find user_id where question1='...' AND question2='...'

  • 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-16T02:48:17+00:00Added an answer on June 16, 2026 at 2:48 am

    This is a case of relational division. Two example query techniques to get what you want:

    SELECT user_id
    FROM   tbl
    WHERE  question_id = 1
    AND    body = 'Text1 1'
    
    INTERSECT
    SELECT user_id
    FROM   tbl
    WHERE  question_id = 2
    AND    body = 'Text1 2';
    

    Or:

    SELECT t1.user_id
    FROM   tbl t1
    JOIN   tbl t2 USING (user_id)
    WHERE  t1.question_id = 1
    AND    t1.body = 'Text1 1'
    AND    t2.question_id = 2
    AND    t2.body = 'Text1 2';
    

    -> sqlfiddle demo

    Find many more under this related question:
    How to filter SQL results in a has-many-through relation

    crosstab() from the additional module tablefunc is just a way to display your data in a modified way. But you are looking for a query technique. It’s not a display issue.
    You can find many examples for crosstab() here on SO, too, with a search like this one.

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

Sidebar

Related Questions

Possible Duplicate: C#/WPF: Toolkit DataGrid - Transpose rows and columns I would like to
Is it possible to transpose an html table (without javascript). I m generating a
Is It possible to Transpose Unlimited rows into column through PIVOT in SQL Server?
Possible Duplicate: Matrix Transpose in Python I have a matrix, say A = [[0,0],[1,1]]
Possible Duplicate: A Transpose/Unzip Function in Python I have a list of sequences, each
Is it possible to transpose a (m,n) matrix in-place, giving that the matrix is
Possible Duplicate: How do I make a request using HTTP basic authentication with PHP
Possible Duplicate: && operator in Javascript In the sample code of the ExtJS web
Possible Duplicate: How can I convert a list<> to a multi-dimensional array? I want
Possible Duplicate: How to do the vector of sets in C++? I want to

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.