[英]Is there a way to check what columns in one dataset exist in another dataset? sql
例如,我有表 1 和表 2,有沒有辦法可以檢查表 1 中的哪些列存在於表 2 中? 謝謝!
雖然最好的解決方案將是 RDBMS 特定的(您沒有指出),但大多數數據庫支持的一般方法是使用information_schema視圖,例如以下將列出 table1 中的列名,這些列名也在 table2 中:
select column_name
from information_schema.columns t1
where t1.table_schema='schemaName' and t1.table_name='table1'
and exists (
select * from information_schema.COLUMNS t2
where t2.column_name = t1.column_name
and t2.table_schema = t1.table_schema
and t2.column_name ='table2'
);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.