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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T11:03:58+00:00 2026-05-31T11:03:58+00:00

I need to export data from a SQL database (some groups use SQL Server,

  • 0

I need to export data from a SQL database (some groups use SQL Server, some Oracle, etc.) into a CSV where I need the id’s from the joined table in a string.

For example, I have a table of Classes and a table of Students. From Classes, I need ID, Name, Section, Time, and from Students I need a string of the ID’s of Students in the class. The results would return the columns: id,name,section,time,student_ids. The ‘student_ids’ column should be a delimited string, such as:

'32,43,53,12,41'

The row output would end up being something like:

"1405,Computer Science,101,12-1:30,'32,43,53,12,41'"

The number of Students per Class is not consistent, there could be one Student, or 20 Students. I thought about using a while loop using SQL Server to obtain this data, or a temp table that aggregates the keys, but I want to know if there is any way using standard SQL to accomplish this, so that the script can be portable.

Notes: I know the output format is not ideal, but the only other option is that we will have to pull a different record for each Class/Student combo, and then will have to aggregate the id’s separately.

  • 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-31T11:03:59+00:00Added an answer on May 31, 2026 at 11:03 am

    Different RDBMS have different ways to perform this kind of query.

    If you are using MySQL, you should take a look at the GROUP_CONCAT aggregate function.

    In Firebird, you have the LIST aggregate function.

    If you are using SQL Server, there are some answered questions in SO under the sql-server-group-concat. The usual approach is using the FOR XML PATH construct. A good example is this: SQL Query to get aggregated result in comma seperators along with group by column in SQL Server

    There are a few ways of doing that in Oracle, there’s a good article here.

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

Sidebar

Related Questions

I need to export a table from SQL Server 2008 from database and then
I have a SQL Server database, i need to export all of the data
I need to export data from a table in database A, then import it
I need to export some data from PostgreSQL to Excel (quick customer wish), and
I need to export the data from 36 SQL tables containing 24GB of data
I need to migrate a database from Postgres 7 to SQL Server 2008. I
I know how to do simple Linq To XML. Export a sql server database
Good morning! I need to move data from Oracle 8i(Enterprise Edition Release 8.1.6.0.0) to
Possible Duplicate: Get script of SQL Server data I want to move some rows
I have a script to export data from MYSQL to a CSV file. the

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.