MySql gurus

Status
Not open for further replies.

louie

New Member
Ok all mysql gurus, I need help here.

I have a table with few fields:

f_1, f_2, f_3, f_4

I want to run a query in mysql to get all the fields together and update the result into f_1

Update `table` set `f_1`=`f_1`. " ".`f_2`." ".`f_3`." ". `f_4`

is this possible directly on the server using Navicat?
 

jmcc

Active Member
Ok all mysql gurus, I need help here.

I have a table with few fields:

f_1, f_2, f_3, f_4

I want to run a query in mysql to get all the fields together and update the result into f_1

Update `table` set `f_1`=`f_1`. " ".`f_2`." ".`f_3`." ". `f_4`

is this possible directly on the server using Navicat?
Not sure about Navicat but look at the CONCAT command.

MySQL AB :: MySQL 5.0 Reference Manual :: 13.2.7 SELECT Syntax

Regards...jmcc
 

louie

New Member
I was looking at that but it only does it on SELECT statement.
I love to do it directly to the database table instead runing the code in PHP, just in case I get an error and everything goes busted.
php will do if I can not run it on the table itself
 

jmcc

Active Member
I was looking at that but it only does it on SELECT statement.
I love to do it directly to the database table instead runing the code in PHP, just in case I get an error and everything goes busted.
php will do if I can not run it on the table itself
Create a temporary table and use INSERT INTO temp_table(f1) SELECT CONCAT(t1.f1,',',t1.f2 etc). Then just replace t1.f1 with the data from temp_tab.

I'm not sure if the UPDATE t1 SET f1=CONCAT(f1,f2,f3,f4) would work cleanly. It might be best to test it on a local setup first before deploying it using php. Backup the tables first though.

Regards...jmcc
 

louie

New Member
I will try that after dinner or in the morning.
Never thought of creating a new table.
The table is duplicate of the original, so i could play with it alright. I also have an xml and xsl copy just in case.
 

louie

New Member
Thanks man.
It worked on the server using Navicat:
Code:
UPDATE `tbl_products` SET `product_name`= CONCAT(`product_name`, ' ', `product_desc`, ' - ', `code_no`, ' ', `group`)
 
Status
Not open for further replies.
Top