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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T00:57:27+00:00 2026-06-01T00:57:27+00:00

can i use GROUP_CONCAT to update table? I have 2 tables i d |

  • 0

can i use GROUP_CONCAT to update table? I have 2 tables
i

d    |  label
------------------------------
1     | ravi,rames,raja
------------------------------
2     |     ravi
------------------------------
3     | ravi,raja
------------------------------
4     | null
------------------------------
5     | null
------------------------------
6     | rames
------------------------------
and 
id    | values
------------------------------
12    | raja
------------------------------
13    | rames
------------------------------
14    | ravi
------------------------------

And i want the result like following table–

id    | label
------------------------------
1     | 12,13,14
------------------------------
2     |     14
------------------------------
3     | 14,12
------------------------------
4     | null
------------------------------
5     | null
------------------------------
6     | 13
------------------------------

but by using the following query –

SELECT `table1`.`id`, GROUP_CONCAT(`table2`.`id` ORDER BY `table2`.`id`) AS label
FROM `table1`
JOIN `table2` ON FIND_IN_SET(`table2`.`values`, `table1`.`nos`) 
GROUP BY `table1`.`id`;

Im getting-

id    | label
------------------------------
1     | 12,13,14
------------------------------
2     | 14
------------------------------
3     | 12,14
------------------------------
6     | 13
------------------------------

I want to keep the null value. otherwise the order of rows will be broken. please help.
sorry for the large font 🙁

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

    You just need a LEFT JOIN to preserve the nulls:

    SELECT `table1`.`id`, GROUP_CONCAT(`table2`.`id` ORDER BY `table2`.`id`) AS label
    FROM `table1`
    LEFT JOIN `table2` ON FIND_IN_SET(`table2`.`values`, `table1`.`nos`) 
    GROUP BY `table1`.`id`;
    

    However, I recommend against updating a table to include comma-separated values in a column. It forces you to use FIND_IN_SET() when querying it, and breaks the ability to index the column, affecting the performance of your queries. The more sustainable action would be to normalize table1 so that it doesn’t include a comma-separated column.

    Update:

    To use GROUP_CONCAT() in an UPDATE statement, you would use a syntax like the following. Substitute your correct table and column names, and in your case, you probably want to replace the entire JOIN subquery with your SELECT statement.

    UPDATE 
      tbl_to_update
      JOIN (SELECT id, GROUP_CONCAT(concatcolumn) AS label FROM tbl GROUP BY id) tbl_concat
         ON tbl_to_update.id = tbl_concat.id
    SET tbl_to_update.column_to_update = tbl_concat.label 
    WHERE <where condition>
    

    So in your case:

    UPDATE
       table1 
       INNER JOIN (SELECT id, GROUP_CONCAT(id) AS label FROM table1 GROUP BY id) table2
          ON FIND_IN_SET(`table2`.`label`, `table1`.`nos`) 
    SET table1.nos = table2.id
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In Sqlite I can use group_concat to do: 1...A 1...B 1...C 2...A 2...B 2...C
When using ColdFusion ORM where you have several tables with relationships can I bind
I have the following five tables: ISP Product Connection AddOn AddOn/Product (pivot table for
I have a user table, and then a number of dependent tables with a
Background My typical use case: # Table id category dataUID --------------------------- 0 A (NULL)
I have a problem with the correct syntax to use UNION and GROUP_CONCAT in
I don't think that I can use ORDER BY clause inside the GROUP_CONCAT function.
I can use stat() to figure out what permissions the owner, group, or others
WHERE gets processed before GROUP BY in the SELECT statement. How can I use
You can use more than one css class in an HTML tag in current

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.