I have a view in MySQL called myview
that has 3 fields: col1
, col1
, col3
.
I would like to figure out where these columns came from, e.g., which table does col1
live in? And col2
? etc.
I can find out where col1
comes from by using
SELECT DISTINCT TABLE_NAME
FROM INFORMATION_SCHEMA.COLUMNS
WHERE COLUMN_NAME = 'col1'
AND TABLE_SCHEMA='lava_mac';
From this I would get 2 matches,
myview
tableWithCol1
This is great, but I really want to extend this query in such a way that I get a result like:
col1 col2 col3
tableWithCo1 tableWithCol2 tableWithCol3
This question is similar, but not the same. Does anyone have any advice? Thanks.