S.Mason S.Mason - 1 month ago 6
MySQL Question

MySQL Change varchar column to type set

I have a table that has data stored in a varchar column:

field varchar :company
example data : AB
SD
AB,SD
SD,AB


The values are only supposed to be one of those combinations (the order does not matter). This column is probably better suited to be type set but it's varchar. I want to convert it to type set with the set's values being AB and SD.

I have a new column called companyFixed with possible values AB, SD. How can I copy the values from the original column into the new proper column?

UPDATE myTable
SET companyFixed = <this row's company values>

Answer

Maybe I haven't understood the question, but as far as I can tell this should work:

UPDATE myTable SET companyFixed = company;

I tried it myself, creating a table with a varchar field, then adding a SET field, and updating from one to the other. It worked.

Comments