I wonder how I can mount a SQL as portable as possible to query for all columns of a table for a specific phrase, like:
Table
ID | Name
Here is how you would concatenate the values in dynamic SQL:
set @Pattern = '%augusto%';
select @q := concat('select * from Table1 ',
'where concat(', group_concat(column_name), ', "") like "', @Pattern, '"'
)
from information_schema.columns c
where table_name = 'Table1';
prepare st from @q;
execute st;
deallocate prepare st;
Of course, dynamic SQL is not particularly portable. The idea would work in most databases. The code would look different.
Tested and working here.
And finally, you can do this with variable substitution (which is the better approach):
select @q := concat('select * from Table1 ',
'where concat(', group_concat(column_name), ', "") like ?'
)
from information_schema.columns c
where table_name = 'Table1';
set @p = '%augusto%';
prepare st from @q;
execute st using @p;
deallocate prepare st;
Also tested (;-).