How to append and pop values in MySql


MySQL SUBSTRING() returns a specified number of characters from a particular position of a given string.

Syntax

SUBSTRING(str, pos, len)

OR

SUBSTRING(str FROM pos FOR len).. eg
UPDATE `lockers` SET `currpass` = SUBSTRING(`currpass`, 1, 8)

this would cut down the string in table currpass to only its first 8 characters

to strip off only last 2 characters

UPDATE `joo_categories` SET `title` = SUBSTRING(`title`, 1, CHAR_LENGTH(title) - 2) WHERE  `title` LIKE  '%∞%'
MySQL CONCAT()
Eg.
UPDATE messages SET message = CONCAT(message,'new text to add')where user_id =1;
OR
UPDATE `rqktr_content` SET `title` = SUBSTRING(`title`, 22) where `title` LIKE 'Watch Naruto Shippuden Episode ___'

If there is a chance that the field may contain a null value, the following works:

UPDATE tb_messages 
SET message =CASE 
WHEN LENGTH(message)>0THEN 
                  CONCAT(message,',','New message content')  
ELSE'New message content' 
END
WHERE user_id =1

or

UPDATE `rqktr_content` 
SET `title` = CONCAT('Watch ', title) 
WHERE `title` LIKE 'Fairy Tail Episode ___'

ORRR

UPDATE `rqktr_content` 
SET `title` = CONCAT('Watch Naruto Shippuude', title) 
WHERE `title` LIKE 'n Episode ___'

 

Hope it helps 🙂
refs:http://www.w3resource.com/
http://stackoverflow.com/questions/9548097/does-mysql-offer-append-content-to-the-value-of-a-column

 

This Post Has One Comment

  1. You really make it appear so easy along with your
    presentation but I find this matter to be actually one thing which I believe I’d by no means understand.
    It seems too complicated and very broad for me. I’m having a look forward
    to your subsequent post, I will attempt to get the cling of it!

Leave a Reply

Close Menu
%d bloggers like this: