I need help with SQL.I need to join 2 tables and fetch particular information. Below is the sql/scenario for reference.
**Input:**Sql1-
select distinct schema,tablename,tbl_cmmt as tabledescription
from test.a
where tbl_cmmt is not null
and
schema is not null
Input data:
schema,tablename,tbl_cmmt
test,sample,test table test1,sample1,test table 2
Sql2-
select schema,table,description from test_descr
join test_class on test_descr.objoid = test_class.oid
join test_namespace on test_class.relnamespace = test_namespace.oid
where kind ='r'
Input data:
schema, table, description
test, sample, table test5, abc , not in use
Output : I want to perform left join on these two sql and fetch all the data from sql1 along with one extra field that is description from sql2.Keys on both tables are schema and table.
Output data
schema, table, tbl_cmmt, description
test, sample, test table, table test1, sample1, test table 2, NULL
1条答案
按热度按时间gxwragnw1#
一个简单的选项是将当前查询用作CTE(或子查询),并在公共列上联接它们: