【发布时间】:2020-09-12 00:47:09
【问题描述】:
我有两个表,table1 和 table2,它们有两个共同的列。
下面给出获取每个表的列名的查询,
查询以从第一个表中获取列:
select column_name from information_schema.columns
where table_schema = 'schema1'
and table_name = 'table1';
查询从第二个表中获取列:
select column_name from information_schema.columns
where table_schema = 'schema2'
and table_name = 'table2';
我需要从 table2 中选择数据,只选择 table1 中的列。
【问题讨论】:
-
您需要使用动态 SQL 来执行此操作。
标签: sql postgresql