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

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???

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.