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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • readnikhil
    New Member
    • Jul 2006
    • 2

    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
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    Have you tried

    UPDATE XYZ SET A=A+B

    not that I am a database expert so take a backup of your database FIRST!

    Comment

    • xpcer
      New Member
      • Jul 2006
      • 51

      #3
      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.

      Comment

      • tomarvijay80
        New Member
        • Nov 2006
        • 10

        #4
        Originally posted by readnikhil
        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.

        Comment

        • bishwadeep
          New Member
          • Nov 2006
          • 12

          #5
          Soln

          May be you should try This:

          Update Tablename set A=(SELECT CONCAT('value of column A', 'value of column B')) where condition...;
          Last edited by bishwadeep; Nov 30 '06, 06:33 AM. Reason: add some message

          Comment

          • jepler
            New Member
            • Oct 2006
            • 4

            #6
            >>>
            Originally posted by tomarvijay80
            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!!!!

            Comment

            Working...