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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:01:39+00:00 2026-06-16T00:01:39+00:00

How to remove duplicate records with merging values? I have the table with id

  • 0

How to remove duplicate records with merging values?

I have the table with id (integer pm key), val1 (text), val2 (text).

Current situation:

------------------

 id  val1    val2

 1.  john     sam
 2.  larry    tom
 3.  john     joe

I want to have:

---------------

 id  val1    val2

 1.  john     sam, joe
 2.  larry    tom
...

Thank you very much for your help.

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

    As far as I know, you can’t do this, you can’t UPDATE and DELETE in one single query. However, you can do this as two UPDATE and DELETE queries like so:

    UPDATE Table1 t1
    INNER JOIN
    (
      SELECT val1, GROUP_CONCAT(val2 SEPARATOR ',') Val2
      FROM Table1
      GROUP BY val1
    ) t2 ON t1.val1 = t2.val1
    SET t1.val2 = t2.val2;
    
    DELETE t
    FROM table1 t
    WHERE id NOT IN
    (
      SELECT ID
      FROM
      (
        SELECT MIN(ID) id, val1
        FROM table1
        GROUP BY val1
       ) sub
     );
    

    This will make the changes you want.

    Note that: You have to put these two queries in one TRANSACTION.

    SQL Fiddle Demo

    These two queries will make your table looks like:

    | ID |  VAL1 |    VAL2 |
    ------------------------
    |  1 |  john | sam,joe |
    |  2 | larry |     tom |
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have to remove duplicate strings from extremely big text file (100 Gb+) Since
I want to remove duplicate records from a table without using temp table how
Possible Duplicate: delete duplicate records in SQL Server I have a table in which
Possible Duplicate: How to remove duplicate records in a table? I'm having one table
Hello I have table name FriendsData that contains duplicate records as shown below fID
I need to remove semi duplicate records from the following table ID PID SCORE
In my table I have so many duplicate records SELECT ENROLMENT_NO_DATE, COUNT(ENROLMENT_NO_DATE) AS NumOccurrences
I'm using MongoDB and need to remove duplicate records. I have a listing collection
I have a table of phone records as such: ID int (Primary Key) company
I have a table that has multiple duplicate records as the following: ID Title

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.