Is there is a way MySQL to get the column names given the value of the column?
For example I have STATES table and CITY table which have 'NAME' as column name.
Say I have 'New York' in both STATES table and CITY table. I want a query which will return the column names of SATES and CITY give 'New York'.
My Expected Output could be like
value column Table
—– —— —–
New York NAME STATES
New York NAME CITY
Above is just an example. In most of the cases i only know the column values and i dont know the Column names or the corresponding table Names. Generally I need not know on the diffrent random schema’s. I am building a question answersing system that will work with multiple databases.
You’re going to have to query the information_schema to get tables and columns similar to this post. I dont’t think MySQL alone is your best bet. If you’re trying to find any table and column that has the value you want that means you’ll be searching every column in every table.
That’s quite an expensive query setup unless you have very simple tables. You’ll need to pull all the table data and then iterate all the tables searching for which columns have the matching value.