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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T03:27:45+00:00 2026-05-24T03:27:45+00:00

Table A ID COLA ———————– A value1 B value1 C value1 Table B ID

  • 0

Table A

ID  COLA    
-----------------------
A   value1      
B   value1
C   value1      

Table B

ID  DETAIL_ID   COL_X   COL_Y
A   0           foo     foo
A   1           bar     bar
B   0           foo     foo

My expected out is something like

ID  COLA    COL_X_0 COL_X_1 COL_Y_0 COL_Y_1
A   value1  foo     bar     foo     bar
B   value1  foo     NULL    foo     NULL
C   value1  NULL    NULL    NULL    NULL

It means the rows of table B will be column values based on DETAIL_ID column.

I tried to write queries for this , but can’t succeed due to following.
Number of DetailID values will NOT be fixed-length.It means I can’t hard-coded the name of the columns.

  • 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-24T03:27:45+00:00Added an answer on May 24, 2026 at 3:27 am

    SQL queries must specify the columns of the result set. That’s fundamental to SQL. Even PIVOT requires that your query specify the columns before you send it to the RDBMS.

    For that reason, it’s difficult and error-prone to create a query that returns rows as columns as you describe, and can adapt as needed to any number of columns.

    Handling dynamic columns must be a two-stage procedure.

    One option is to make the two stages be:

    1. Write application code to build the SQL query dynamically, based on the distinct values found in the data. This requires an extra query to discover what values exist so you can build the query.
    2. Execute the SQL query and retrieve the results.

    The other option is to make the two stages be:

    1. Run a more plain SQL query, that fetches rows as rows, as they are stored in the database.
    2. Write application code to post-process the results, collecting individual values from rows into an expanding set of columns based on the values found. This does not require an extra query as the first design does.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a HTML table like below: ColA ColB ColC ColD ColE ColF Checked
Suppose I have a table like this.. ColA ColB ColC ---------------------- A 100 1
My table structure looks like this: tbl.users tbl.issues +--------+-----------+ +---------+------------+-----------+ | userid | real_name
Let's say there's a table created as follows: create table testTable ( colA int
I have a lookup table in Excel with ColA and ColB : ColA ColB
Data in Table : ItemCode ItemName ItemGroup SFD Softdrink NULL CCL Coco Cola SFD
I have a table with the following column & value: ColA = 8765 ColB
Basically, if I have a table with composite indices (colA, colB, colC) and (colB,
I have a table as follows: colA colB(unique) colC --------------------------------- 1 1449 0.50000000 1
I have a table with some data in it: ColA | ColB | ColC

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.