469,636 Members | 1,680 Online

concatenating two fields and storing the value in a single field using mysql

plz help me solving the problem.

i am using a table named XYZ in MYSQL
i have columns A B C D E

now i want 2 concatenate the values of column A & B and store this value in column A, such that new values in column A is concatenation of values of A + values of B.
plz sumone help me in writing query
Jul 17 '06 #1
5 8171
Banfa
9,064 Expert Mod 8TB
Have you tried

UPDATE XYZ SET A=A+B

not that I am a database expert so take a backup of your database FIRST!
Jul 17 '06 #2
xpcer
51
I think, it depends of the data type of the field.
If the data type is numeric you can use aritmatic operation such as A+B, but if you use another data type such as varchar u can use CAST or CONVERT function that available in mysql.

Can u tell me what data type you choose for the field, may be i can help you.
Jul 18 '06 #3
plz help me solving the problem.

i am using a table named XYZ in MYSQL
i have columns A B C D E

now i want 2 concatenate the values of column A & B and store this value in column A, such that new values in column A is concatenation of values of A + values of B.
plz sumone help me in writing query
Solution::

select concat(A,' ',B) as A from XYZ ;

If you want to see separate values in column A then

select concat(A,' , ',B) as A from XYZ ;

Hope this solve ur problem.
Nov 30 '06 #4
May be you should try This:

Update Tablename set A=(SELECT CONCAT('value of column A', 'value of column B')) where condition...;
Nov 30 '06 #5
>>>
Solution::

select concat(A,' ',B) as A from XYZ ;

If you want to see separate values in column A then

select concat(A,' , ',B) as A from XYZ ;

Hope this solve ur problem.

I don't know if it solved his problem, but it solved mine!! Thank you!!!!
Jan 5 '07 #6