Q

Combining two fields

A MySQL expert explains how to combine the text and number fields to create a third field.

I can't figure out how to take the data (text) from two fields (varchar) and put them together in a third field. Right now, I have:
field1: abcd
field2: 1111

I'd like to have:

field3: abcd1111

Can you help me?

Use:
UPDATE table SET field3 = CONCAT(field1, field2)

Check out this list of string functions. This concatenation can be done automatically by adding BEFORE triggers on INSERT and UPDATE.

Within the trigger, set

NEW.field3 = CONCAT(NEW.field1, NEW.field2)

You can find out more about triggers in MySQL at: http://dev.mysql.com/doc/refman/5.0/en/triggers.html.

This was last published in March 2007

Dig Deeper on Open source databases

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

Start the conversation

Send me notifications when other members comment.

By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Please create a username to comment.

-ADS BY GOOGLE

SearchDataCenter

SearchServerVirtualization

SearchCloudComputing

SearchEnterpriseDesktop

Close