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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T19:08:10+00:00 2026-06-10T19:08:10+00:00

I load data from SQL to CSV file. And my csv records are in

  • 0

I load data from SQL to CSV file. And my csv records are in the following way.

Eid  ename  desig  sourceD  location  
1     Ralf   PM      1        UK  
1     Ralf   PM      1        USA  
2     Marty  PL      3         GBR  
3     Levis  BA      5        UK  
4     Ricky  BI      7        RSA  
4     Ricky  BI      7        FRA 

now i want to combine EID 1 and 4 into single rows. My output has to be in the following way

Eid  ename  desig  sourceD  location  
1     Ralf   PM      1        UK, USA  
2     Marty  PL      3         GBR  
3     Levis  BA      5        UK  
4     Ricky  BI      7        RSA, FRA   

I have only CSV File i dont have any sql Query or anything.

  • 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-10T19:08:12+00:00Added an answer on June 10, 2026 at 7:08 pm

    SQL Fiddle

    SQL Query

        select c1.Eid, c1.ename,c1.desig,c1.sourceD,
        (   SELECT x.location + ', '
            FROM Contacts x
            WHERE c1.Eid = x.Eid
            ORDER BY x.location
            FOR XML PATH ('')
        ) as Locations
    from Contacts c1
    group by c1.Eid, c1.ename,c1.desig,c1.sourceD
    

    Working ?

    If you want without comma in the end:

        SELECT c1.Eid, c1.ename,c1.desig,c1.sourceD,
       LEFT( (   SELECT x.location + ', '
            FROM Contacts x
            WHERE c1.Eid = x.Eid
            ORDER BY x.location
            FOR XML PATH ('')
        ),LEN((   SELECT x.location + ', '
            FROM Contacts x
            WHERE c1.Eid = x.Eid
            ORDER BY x.location
            FOR XML PATH ('')
        ))-1) AS Locations
    FROM Contacts c1
    GROUP BY c1.Eid, c1.ename,c1.desig,c1.sourceD
    

    This Query will let you avoid lenght 0:

        SELECT c1.Eid, c1.ename,c1.desig,c1.sourceD,
       LEFT( (   SELECT x.location + ', '
            FROM Contacts x
            WHERE c1.Eid = x.Eid
            ORDER BY x.location
            FOR XML PATH ('')
        ),CASE WHEN LEN((   SELECT x.location + ', '
            FROM Contacts x
            WHERE c1.Eid = x.Eid
            ORDER BY x.location
            FOR XML PATH ('')
        ))=0 THEN 1 ELSE LEN((   SELECT x.location + ', '
            FROM Contacts x
            WHERE c1.Eid = x.Eid
            ORDER BY x.location
            FOR XML PATH ('')
        )) END -1) AS Locations
    FROM Contacts c1
    GROUP BY c1.Eid, c1.ename,c1.desig,c1.sourceD
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In order to load data (from a CSV file) into an Oracle database, I
I'm trying to load data from an external csv file that needs to be
I'm trying to load data from a CSV file into a MySQL database, and
I am trying to load data from SQL to No-SQL i.e Cassandra. but somehow
I have SSIS package which pulls the data from Excel(.xls) file and load the
When using Cucumber with Capybara, I have to load test database data from SQL
I am trying to load data from database (either MS Access or SQL server)
I'm using MySQL's LOAD DATA LOCAL INFILE SQL statement to load data from a
I am using a asp.net grid view to load data from my sql data
I want to load data from several CSV documents in a database. The problem

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.