Sæt skabe-tabellen i sætningen:
PREPARE STMT FROM "CREATE TABLE tab_derived_1 SELECT * FROM tab_1 WHERE predict_var = '4' or predict_var = '2' union
(SELECT * FROM tab_1 WHERE predict_var = '0' or predict_var = '1' ORDER BY RAND() limit ? )" ;
EXECUTE STMT USING @sample;
Og hvis du ønsker at returnere resultaterne, ikke bare gemme dem i en tabel, bare lav en sidste
SELECT * FROM tab_derived_1