Hello Stack Overflow community,
I would like to consolidate multiple fields within the same table. Among other fields,'Table1' contains a number of fields each for a different US state. For a given 'ID' (primary key), a US state field will return a '1' for the corresponding state to that ID and will return 'null' for the rest of the state fields. Any given state may be applicable for multiple ID's.
Specifically, I would like to consolidate all the state fields into one field that will return the corresponding state for a given ID instead of having an unnecessary amount of state fields that will make the data harder to work with. I've visually outlined the existing format and desired format below. Any help is greatly appreciated!
Visual Examples of Existing and Desired Format.
I tried the following which did not work in creating the desired format:
INSERT INTO Table1 (ID, Cust_St_NY, Cust_St_IL, Cust_St_...) SELECT GROUP CONCAT (ID, Cust_St_NY, Cust_St_IL, Cust_St_...) FROM Table1 GROUP BY ID