我希望得到一个名为" a"和另一个名为" b"
的专栏例如:
SELECT DISTINCT tables.name FROM tables_colums INNER JOIN tables INNER JOIN colums
ON tables.id = tables_colums.table_id AND colums.id = tables_colums.column_id
WHERE columns.name = "a" AND columns.name = "b"
答案 0 :(得分:2)
您可以在information_schema
数据库中找到元数据。列的medadata存储在information_schema.columns
表中。
select TABLE_SCHEMA, TABLE_NAME
from information_schema.columns
where COLUMN_NAME in ('a', 'b')
group by TABLE_SCHEMA, TABLE_NAME
having count(*) = 2
如果您只需要来自特定数据库(架构)的表:
select TABLE_NAME
from information_schema.columns
where TABLE_SCHEMA = 'my_db'
and COLUMN_NAME in ('a', 'b')
group by TABLE_NAME
having count(*) = 2