mardi 9 novembre 2021

How do I copy a table if a specific condition is met?

I can determine whether a condition is met by using the following:

SELECT id FROM admin WHERE firstname='John' INTO @tmp
SELECT IF (@tmp >= 1, "success", "fail")

But how would I create a copy of the table if the same condition is met? eg.

CREATE TABLE admin_copy LIKE admin
INSERT admin_copy
SELECT * FROM admin;

Aucun commentaire:

Enregistrer un commentaire