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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T18:16:02+00:00 2026-06-11T18:16:02+00:00

Possible Duplicate: how to retrieve two columns data in A,B format in Oracle Suppose

  • 0

Possible Duplicate:
how to retrieve two columns data in A,B format in Oracle

Suppose I have a table like this:

NAME          GROUP_NAME
name1         groupA
name2         groupB
name5         groupC
name4         groupA
name3         groupC

I’d like to have a result like this:

GROUP_NAME     NAMES
groupA         name1,name4
groupB         name2
groupC         name3,name5

If there were only one column in the table, I could concatenate the records by doing the following, but with grouping in the context, I really don’t have much idea.

Concatatenating one column table:

SELECT names 
FROM (SELECT SYS_CONNECT_BY_PATH(names,' ') names, level
      FROM name_table

      START WITH names = (SELECT names FROM name_table WHERE rownum = 1)
      CONNECT BY PRIOR names < names
      ORDER BY level DESC)
      WHERE rownum = 1 

Updated:

I now have a solution by using LISTAGG:

SELECT
group_name,
LISTAGG(name, ', ')
WITHIN GROUP (ORDER BY GROUP) "names"
FROM name_table
GROUP BY group_name

Still interested in a more “general” solution for cases when LISTAGG is not available.

  • 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-11T18:16:03+00:00Added an answer on June 11, 2026 at 6:16 pm

    Consider using LISTAGG function in case you’re on 11g:

    select grp, listagg(name,',') within group( order by name ) 
      from name_table group by grp
    

    sqlFiddle

    upd: In case you’re not, consider using analytics:

    select grp,
        ltrim(max(sys_connect_by_path
           (name, ',' )), ',')
            scbp
      from (select name, grp,
                row_number() over
               (partition by grp
                order by name) rn
             from tab
              )
    start with rn = 1
    connect by prior rn = rn-1
    and prior grp = grp
      group by grp
      order by grp
    

    sqlFiddle

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

Sidebar

Related Questions

Possible Duplicate: What format is this? How do i retrieve this one. I'm not
Possible Duplicate: How to retrieve user's current city name? using the following methods i
Possible Duplicate: Retrieve Table Row Index of Current Row <html> <script> function addValue(a) {
Possible Duplicate: Retrieve column names from java.sql.ResultSet I have query which returns the result
Possible Duplicate: Retrieve JIT output Is this possible to do, and if so how
Possible Duplicate: Fastest way to retrieve a <title> in PHP Suppose there is a
Possible Duplicate: What is the reg expression for this using javascript How to retrieve
I want to retrieve all case-insensitive duplicate entries from an array. Is this possible
Possible Duplicate: Post data and retrieve the response using PHP Curl? I want to
Possible Duplicate: Retrieve (or simulate) full query from PDO prepared statement I can't figure

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.