两张表的关联查询,公司给的源sql语句如下,但是查出来的是第一张表的数据,第二张表中的数据就没有
两张表的关联查询,公司给的源sql语句如下,但是查出来的是第一张表的数据,第二张表中的数据就没有查出来,在大体不修改的情况下,怎么改?selectCOLUMN_NAMEa...
两张表的关联查询,公司给的源sql语句如下,但是查出来的是第一张表的数据,第二张表中的数据就没有查出来,在大体不修改的情况下,怎么改?
select COLUMN_NAME as NAME, COMMENTS as COMMENTS from USER_COL_COMMENTS where ( (table_name='LAS_CTRCT' or table_name='LAS_CTRCT_OPPOSITE' ) and ( column_name='CODE' or column_name='NAME' or column_name='CUR_STATUS' or column_name='APPL_USER_NAME' or column_name='TRACK_NAME' or column_name='IS_FOREIGN' or column_name='TARGET' or column_name='PAY_DIRCT' or column_name='CURRENCY' or column_name='TTL_PRC_LOWER' or column_name='TTL_PRC_UPPER' or column_name='IS_STD' or column_name='' or column_name='RISK_CAT_ID' or column_name='PROPERTY' or column_name='PERF_START' or column_name='PERF_END' or column_name='IS_AUTH' or column_name='CREATE_TIME' or column_name='MODIFY_TIME' or column_name='CAT_NAME' and column_name='FULL_NAME') ) 展开
select COLUMN_NAME as NAME, COMMENTS as COMMENTS from USER_COL_COMMENTS where ( (table_name='LAS_CTRCT' or table_name='LAS_CTRCT_OPPOSITE' ) and ( column_name='CODE' or column_name='NAME' or column_name='CUR_STATUS' or column_name='APPL_USER_NAME' or column_name='TRACK_NAME' or column_name='IS_FOREIGN' or column_name='TARGET' or column_name='PAY_DIRCT' or column_name='CURRENCY' or column_name='TTL_PRC_LOWER' or column_name='TTL_PRC_UPPER' or column_name='IS_STD' or column_name='' or column_name='RISK_CAT_ID' or column_name='PROPERTY' or column_name='PERF_START' or column_name='PERF_END' or column_name='IS_AUTH' or column_name='CREATE_TIME' or column_name='MODIFY_TIME' or column_name='CAT_NAME' and column_name='FULL_NAME') ) 展开
2个回答
展开全部
你这个代码是从一个表设置说明的表中查询两个表的各列说明,但在条件中,and后面的括号里所有的or的条件,约定了一些条件。
你看你的结果里,第3行和第19行都是CODE,这个就说明一个是表'LAS_CTRCT'里的,一个是表'LAS_CTRCT_OPPOSITE'里的。
你可以将代码改为以下看看(这个是看查询出的结果列是属于哪个表的):
select table_name as 表名, COLUMN_NAME as 列名, COMMENTS as 说明 from USER_COL_COMMENTS
where ( (table_name='LAS_CTRCT' or table_name='LAS_CTRCT_OPPOSITE'
)
and ( column_name='CODE' or column_name='NAME'
or column_name='CUR_STATUS' or column_name='APPL_USER_NAME'
or column_name='TRACK_NAME' or column_name='IS_FOREIGN'
or column_name='TARGET' or column_name='PAY_DIRCT'
or column_name='CURRENCY' or column_name='TTL_PRC_LOWER'
or column_name='TTL_PRC_UPPER' or column_name='IS_STD' or column_name=''
or column_name='RISK_CAT_ID' or column_name='PROPERTY' or column_name='PERF_START'
or column_name='PERF_END' or column_name='IS_AUTH' or column_name='CREATE_TIME'
or column_name='MODIFY_TIME' or column_name='CAT_NAME' and column_name='FULL_NAME')
)
或者你直接改成以下,来查看'LAS_CTRCT' 和'LAS_CTRCT_OPPOSITE'两个表中的所有列:
select table_name as 表名, COLUMN_NAME as 列名, COMMENTS as 说明 from USER_COL_COMMENTS where table_name='LAS_CTRCT' or table_name='LAS_CTRCT_OPPOSITE'
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询