Jump to content

Adding text to many rows in a column in the one table.


BillyMako

Recommended Posts

Hi,

I want to be able to insert some text at the beginning of many rows in the one table.

For example if I want to add the text: "A power cable is included" to all rows in the 'products_description' column in the 'products_description' table WHERE 'products_name' begins with 'V'. 

How would I do the SQL code???

Thankyou

Link to comment
Share on other sites

Thanks it worked!

 

One more problem, when I want to change the sentence I have just added to all columns like 'V%' how can I delete and then add a different sentence or alter that sentence without changing the rest of the stuff that is after it???

Link to comment
Share on other sites

Hi

 

You can manipulate the string using normal functions, such as :-

 

update `products_description`
SET `products_description` = concat('The case is available in bright pink',substr(`products_description`,24))
WHERE 'products_name' like 'V%'

 

However this would likely get messy pretty rapidly (ie, what happens when you have put in an extra phrase at the start for any product name beginning 'Ve'?). It might be better to split off all the bits of description into a separate table, one line per item and then use GROUP_CONCAT to retrieve the full description when required. You can then just add / delete lines of description easily.

 

All the best

 

Keith

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.