eozzy
eozzy

Reputation: 68710

Updating column based on existing fields

I created a new fields and I need to update it based on existing fields. Wondering if MYSQL can do this using variables or do I have to use PHP? Since the table is huge (300k+ rows, I assume its best done with a query itself is possible)

Current:

+-----+--------+--------------+
| pid |  mfr   |     pnum     |
+-----+--------+--------------+
|     | MCAFEE | HIDYFM-AA-DA |
+-----+--------+--------------+

Expected:

+-----------------------+--------+--------------+
|          pid          |  mfr   |     pnum     |
+-----------------------+--------+--------------+
| MCAFEE___HIDYFM-AA-DA | MCAFEE | HIDYFM-AA-DA |
+-----------------------+--------+--------------+

Upvotes: 0

Views: 41

Answers (2)

Amar1990
Amar1990

Reputation: 11

You can do this by mysql query. like this

update  example set pid = concat(mfr ,"__",pnum);

where example is table name

Upvotes: 1

Gulmuhammad Akbari
Gulmuhammad Akbari

Reputation: 2036

Just concatenate the two fields and set to pid

UPDATE table_name SET pid=CONCAT(mfr,"___",pnum)

Upvotes: 2

Related Questions