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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T00:01:46+00:00 2026-05-12T00:01:46+00:00

I have one table that has sales records and another table that has additional

  • 0

I have one table that has sales records and another table that has additional details on each record. What I need to do is build a query that will query the first table and, for each record, list additional details in a virtual column, like this:
“Additional detail #1 for record 1: some additional detail; Additional detail #2 for record 1: more additional details;…” Basically, this column is a concatenation of all additional field record values.

There is no limit on how many additional details (records in the additional details table) one record from the primary table can have.

Do you have any suggestions on how to do this?

  • 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-12T00:01:47+00:00Added an answer on May 12, 2026 at 12:01 am

    In MySQL:

    SELECT  s.*,
            GROUP_CONCAT(detail)
    FROM    sales s
    JOIN    details d
    ON      d.sale_id = s.id
    GROUP BY
            s.id
    

    In SQL Server:

    SELECT  s.*,
            (
            SELECT  CASE WHEN ROW_NUMBER() OVER (ORDER BY sale_id) = 1 THEN ', ' ELSE '' END + detail
            FROM    details d
            WHERE   d.sale_id = s.id
            FOR XML PATH('')
            )
    FROM    sales s
    

    In PostgreSQL:

    SELECT  s.*,
            ARRAY_TO_STRING (
            ARRAY
            (
            SELECT  detail
            FROM    details d
            WHERE   d.sale_id = s.id
            ), ', ')
            )
    FROM    sales s
    

    In Oracle:

    WITH q AS (
            SELECT  d.sale_id, d.detail,
                    ROW_NUMBER() OVER (PARTITION BY d.sale_id ORDER BY d.detail) AS rn
            FROM    sales s
            JOIN    details d
            ON      d.sale_id = s.id
            )
    SELECT  *
    FROM    (
            SELECT  *
            FROM    q
            MODEL
            PARTITION BY
                    (sale_id)
            DIMENSION BY
                    (rn)
            MEASURES
                    (detail, detail AS group_concat, 0 AS mark)
            RULES UPDATE (
                    group_concat[rn > 1] =  group_concat[CV() - 1] || ', ' || detail[CV()],
                    mark[ANY] = PRESENTV(mark[CV() + 1], 0, 1)
                    )
            )
    WHERE   mark = 1
    ORDER BY
            id
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 124k
  • Answers 124k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Are you running on OS 3.0? I saw the same… May 12, 2026 at 1:19 am
  • Editorial Team
    Editorial Team added an answer It looks like you need to register Apache::Session::Memcached with Apache::Session::Wrapper,… May 12, 2026 at 1:19 am
  • Editorial Team
    Editorial Team added an answer Use DATENAME or DATEPART: SELECT DATENAME(dw,GETDATE()) -- Friday SELECT DATEPART(dw,GETDATE())… May 12, 2026 at 1:19 am

Related Questions

I'm maintaining a multiuser Access 2000 DB linked to an MSSQL2000 database, not written
I have a dataset with multiple tables. One table in particular has one record
The problem I have is this: I have a table (just an example) with
I have a table containing user input which needs to be optimized. I have
I've just begun diving into data warehousing and I have one question that I

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.