SET @sql_query := '';
SELECT GROUP_CONCAT(CONCAT('SELECT * FROM `', table_schema, '`.`', table_name, '`') SEPARATOR ' UNION ALL ')
INTO @sql_query
FROM information_schema.tables
WHERE table_schema IN ('database1', 'database2', 'database3')
AND table_name LIKE 'test_[1-3][a-z]%';
SET @final_query := CONCAT('SELECT * FROM (', @sql_query, ') AS combined_table');