Take the 2-minute tour ×

I have a table that has a number of columns. For each row, I'd like to select three columns (PAR_BOOK, PAR_PAGE, PAR_LINE) and concatenate the contents of those three columns into a new fourth column (APN).

So, if PAR_BOOK=0108, PAR_PAGE=291 and PAR_LINE=07, APN should be 010829107

Make sense?

But, I'm unsure of what query I should use to do this. I need the results stored back in the same table as it needs to be ultimately exported out as a csv to work with the program that's going to map the data.

share|improve this question
Show your query. Inserting into the same table is no problem at all as MySQL holds the selected rows in a temporary table. –  AndreKR Oct 8 '12 at 18:28
Why do you want to store that value in the first place? Information that can be reconstructed based on the existing data should not be stored. You could create a view to achieve this. –  a_horse_with_no_name Oct 8 '12 at 18:30
Not that I should have to explain myself, but it's being exported as a csv for use in a mapping application. All of which I explained above. –  DrDavid Oct 8 '12 at 18:44
add comment

2 Answers

up vote 4 down vote accepted

Assuming your fourth column is already in the table, you would use the following update query:

UPDATE YourTable

If your fourth column is not present in the table yet, you should use the ALTER TABLE statement to add it first before running the UPDATE statement:

share|improve this answer
I tried the command, and it looked like it would work, but, it's actually ADDING the numbers; I need it concatenated instead.. –  DrDavid Oct 8 '12 at 18:39
Please use CONCAT method instead, as updated in the response. –  Vikdor Oct 8 '12 at 18:41
add comment

Inserting into the same table with INSERT INTO ... SELECT ... is no problem at all. MySQL holds the selected rows in a temporary table.

share|improve this answer
add comment

Your Answer


