0

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;

1 Answer 1

5

why do you dont try to insert the categories direct like this:

INSERT INTO `categories`
(
    title
)
SELECT DISTINCT
    `category`
FROM `tablename`
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.