Suppose I have the following table with a single column:
Table_1
----------- | nameCol | ----------- | A | | A | | B | | C |
You could use a dynamic query:
SELECT CONCAT( 'CREATE TABLE Table_2 (', GROUP_CONCAT(DISTINCT CONCAT(nameCol, ' VARCHAR(50)') SEPARATOR ','), ');') FROM Table_1 INTO @sql; PREPARE stmt FROM @sql; EXECUTE stmt;
Please see fiddle here.