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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T23:40:52+00:00 2026-05-30T23:40:52+00:00

I have new problem with query: I want to update column ‘column’ depending on

  • 0

I have new problem with query:

I want to update column ‘column’ depending on id with some new data:

UPDATE table SET column = CASE 
    WHEN id = 2 THEN CONCAT(`column`, ',7') 
    WHEN id = 3 THEN CONCAT(`column`, ',10')    
    ELSE column
    END;

Unfortunatelly, adding new values to column must have a comma at the beginning because column stores data as comma separated values.
For example it looks like this:

id | column
-------------
 2 | 3, 1, 20
 3 | 1, 5

After executing a query I get:

id | column
-------------
 2 | 3, 1, 20, 7
 3 | 1, 5, 10

It’s all good till now. Unfortunatelly if I update column that is empty it all starts with comma and it looks like this:

id | column
-------------
 2 | ,7
 3 | ,10

It causes some problems when grabing data from db becuase when i explode() it, it makes first array value empty. I want to remove such first commas when updating table.
I guess I should make some ‘if’ statements that check length of ‘column’ (with char_length) and if it’s empty update without first, starting comma.
Can you help me with proper syntax?

Summary:
How to make proper query that updates column as described above with values starting with comma if ‘column’ exists. If ‘column’ is empty update it with variable without starting comma.

  • 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-30T23:40:53+00:00Added an answer on May 30, 2026 at 11:40 pm

    How about this:

    UPDATE table SET column = CASE 
        WHEN id = 2 THEN CONCAT(`column`, IF( CHAR_LENGTH(column)=0, '', ',' ), '7' ) 
        WHEN id = 3 THEN CONCAT(`column`, IF( CHAR_LENGTH(column)=0, '', ',' ), '10')    
        ELSE column
        END;
    

    MySQL’s reference manual: CHAR_LENGTH(..) and IF(..,..,..).

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

Sidebar

Related Questions

I'm new to python and have hit a problem with an SQL query I'm
I have a problem at some customer pc's (new Dell PCs) windows XP Professional
i am new in JSP,i have some problem with the following code : <%@
I have SQL table that has a varchar(8) column that occasionally has binary data
I have a problem with mysql query .. I have a table in the
I need to update some AD querying code and want to use the new
I have two set of arrays in different MYSQL table. This what I want
I have a query problem. I have a table of agents that do things.
Some background: I have an database that I want to use linq-to-sql to update
Following on from my previous question [link text][1] , I have a new 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.