Mysql
 sql >> Database >  >> RDS >> Mysql

MYSQL:aggiungi o inserisci un valore in una colonna a seconda che sia vuota o meno

https://dev.mysql.com/doc /refman/5.0/en/insert-on-duplicate.html

Ciò significa nel tuo caso:

INSERT INTO tablename (id,columnname) VALUES (1,'//string')
  ON DUPLICATE KEY UPDATE columnname=CONCAT(columnname,'//string');

http://sqlfiddle.com/#!9/bd0f4/1

AGGIORNAMENTO Solo per mostrarti le tue opzioni:

http://sqlfiddle.com/#!9/8e61c/1

INSERT INTO tablename (id, columnname) VALUES (1, '//string')
  ON DUPLICATE KEY UPDATE columnname=CONCAT(columnname,'//string');

INSERT INTO tablename (id, columnname) VALUES (1, '//string')
  ON DUPLICATE KEY UPDATE columnname=CONCAT(columnname,'//string');

INSERT INTO tablename (id, columnname) VALUES ((SELECT id FROM tablename t WHERE columnname='blahblah'), '//string')
  ON DUPLICATE KEY UPDATE columnname=CONCAT(columnname,'//string');

INSERT INTO tablename (id, columnname) VALUES ((SELECT id FROM tablename t WHERE id=2), '//string')
  ON DUPLICATE KEY UPDATE columnname=CONCAT(columnname,'//string');

INSERT INTO tablename (id, columnname) VALUES ((SELECT id FROM tablename t WHERE columnname='newone'), '//newone')
  ON DUPLICATE KEY UPDATE columnname=CONCAT(columnname,'//newone');