Sätt skapa tabellen i satsen:
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;
Och om du vill returnera resultaten, inte bara lagra dem i en tabell, gör bara en sista
SELECT * FROM tab_derived_1