在选择中选择Oracle SQL

扎格韦

因此,我reason在表1中标识了某种ID。我需要编写查询,该查询从表2中写出原因的从属含义。我希望我的英语不好足以解释我的问题。

表格1

    id  reason
  --------------
    1     1
    2     2
    3     1

表2

domain         value  meaning
------------------------------
table1.reason    1    example1
table1.reason    2    example2

我想这个选择,但我得到的错误“ORA-01427:单行子查询返回多个行”,但如果我添加max()t2.meaning它只返回我的意思是例题,因为最大值= 2

select 
    t1.id
    (select t2.meaning
    from table2 t2, table1 t1
    where t2.value = t1.reason
    and t2.domain = 'table1.reason') as reason
from table1;

我怎么解决这个问题?

戈登·利诺夫

我很确定您只想要一个相关的子查询,而不是一个join

select t1.id
       (select t2.meaning
        from table2 t2
        where t2.value = t1.reason and
              t2.domain = 'table1.reason'
       ) as reason
from table1;

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章