BillyMako Posted May 5, 2009 Share Posted May 5, 2009 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 Quote Link to comment Share on other sites More sharing options...
kickstart Posted May 5, 2009 Share Posted May 5, 2009 Hi Something like this should do it- update `products_description` SET `products_descriptio` = concat('A power cable is included',`products_description`) WHERE 'products_name' like 'V%' All the best Keith Quote Link to comment Share on other sites More sharing options...
BillyMako Posted May 6, 2009 Author Share Posted May 6, 2009 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??? Quote Link to comment Share on other sites More sharing options...
kickstart Posted May 6, 2009 Share Posted May 6, 2009 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.