Letakkan tabel buat dalam pernyataan:
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;
Dan jika Anda ingin mengembalikan hasilnya, tidak hanya menyimpannya di tabel, lakukan saja final
SELECT * FROM tab_derived_1