Although another answer give a solution, I believe I did not want to normalize the table to get the result, you just want the facilitator to assemble the query. Altering the modeling because of this would be absurd.
In the comments asked about the type of the columns. I do not know what fancy solutions are thinking but I doubt it is something nice to use.
Data dictionary
The only way I see of doing this is to use one data dictionary. I’m not saying you should.
This is an old technique that almost everyone ignores, for one reason or another. Almost everything (complex) I do in database is on top of a data dictionary, so it gives me ease and flexibility.
In it you will have information about how the database is structured. This is how it controls access to the data. If you need to change the structure of the database, the change will be made in the dictionary and an application will apply the changes starting from the modification made in the dictionary.
Among the numerous advantages it can also be used to assemble their darlings as you wish.
In this case the columns would have a grouping or labeling form indicating that these columns have a specific meaning, when adding a new column to this table in the data dictionary with this tag, your code will know that to generate the query will need to pick up all columns with the tag and immediately you will be using it.
Making the data dictionary system is not something simple and if it is only for this too is nonsense. But there is no simple solution.
I won’t go into more detail about the data dictionary which is not the focus of the question, but who wants superior applications should learn to work with a.
filtro_x columns are all of the same type?
– ramaral
https://dev.mysql.com/doc/refman/5.0/en/columns-table.html. see if this helps
– Motta
Enter more information from your database to answer your answer completely. (we don’t know if filter is string or we don’t know what else is in the filter table) The best way to do this is to put the filters as the same relationship table. Use normalization techniques in the code. http://imasters.com.br/artigo/7020/banco-data/
– Felipe Jorge
I don’t understand. You can post a DDL (i.e. the
CREATE TABLE
) with a summary of what is in this filter table? Your data itself is in another table, right? What is the difference in structure between this other table and the tablefiltros
?– user25930
Make sure your logic is correct... As a rule, a database table is not something that should be changed every little bit, let alone programmatically.
– Dinei
I have the habit that when the problem is no longer a problem, forget it, even if third parties are involved. Thanks for letting me know, I forgot this appointment here, Thanks!
– Ale