Reputation: 5947
I'm trying to move enums from a table into their own table, the easiest way would be to run an SQL query which I figured I might use a WHILE loop for, but having never used one before the below obviously doesn't work. Is it possible to do something as the following:
WHILE (SET @cat = (SELECT DISTINCT `category` FROM `tablename`))
DO
BEGIN
INSERT INTO `categories` (title) VALUES (@cat);
END;
END WHILE;
Upvotes: 0
Views: 5148
Reputation: 7887
why do you dont try to insert the categories direct like this:
INSERT INTO `categories`
(
title
)
SELECT DISTINCT
`category`
FROM `tablename`
Upvotes: 5