0

I need one help.I need to join one new value with existing value present inside database column using PHP and Mysql.I am explaining my table below.

db_admin

id    supplier_id

1      2,3,4,5,6

Here in supplier_id column i have some value like 2,3,4,5,6.suppose i need to add another value lets say 7 with the existing supplier_id with comma operator finally the result will be 2,3,4,5,6,7 So i need query for that.Please help me.

3
  • 2
    update db_admin set supplier_id=concat(supplier_id, ',7'); Commented Mar 29, 2016 at 11:34
  • 5
    Fix your data structure to have a proper junction table (one row per id and supplier_id). Then use insert. Commented Mar 29, 2016 at 11:35
  • Normalize your database to 1NF and you can do this easily. Check en.wikipedia.org/wiki/First_normal_form#Atomicity for why your design isn't a good idea. Commented Mar 29, 2016 at 11:39

2 Answers 2

0

Just Use Following query using Concat

UPDATE `db_admin` SET `supplier_id` = concat(supplier_id, ',7') WHERE `id` = 1;
Sign up to request clarification or add additional context in comments.

Comments

0

As Gordon Linoff stated you shouldn't try to handle it in this manner. Make a proper linking table between this table and the supplier table.

https://en.wikipedia.org/wiki/Associative_entity

You can add the 7 now, but tomorrow you want to remove the 4 and then you have a new problem.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.