Abres 1 (
y cierra 2 )
. Eliminar el último:
SELECT CONCAT('changes',year,month) FROM changes
Editar
la segunda declaración probablemente debería ser
SET @x := SELECT * FROM (@b) as b;
Eso funciona, pero no estoy seguro si eso es lo que quieres:
SET @b := 'SELECT CONCAT(''changes'',`year`,`month`) FROM whichchanges';
SET @x := 'SELECT * FROM (SELECT CONCAT(''changes'',`year`,`month`) FROM whichchanges) as b';
Prepare stmt FROM @b;
Prepare stmt FROM @x;
Execute stmt;
Editar2
Si te entendí bien, estás buscando esa única consulta:
select * from changes
where change_column in (select distinct concat(`year`, `month`) from whichchanges)
Editar3
select @b := group_concat(concat(' select * from changes', `year`, `month`, ' union ') separator ' ') as w from whichchanges;
set @b := left(@b, length(@b) - 6);
Prepare stmt FROM @b;
Execute stmt;