选择中的Oracle SQL选择

选择中的Oracle SQL选择,sql,oracle,plsql,Sql,Oracle,Plsql,因此,我在表1中将reason标识为某种ID。我需要编写一个查询,从表2中写出原因的归属意义。我希望我糟糕的英语足以解释我的问题 表1 id reason -------------- 1 1 2 2 3 1 表2 domain value meaning ------------------------------ table1.reason 1 example1 table1.reason 2

因此,我在表1中将
reason
标识为某种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:单行子查询返回多行”,但如果我在
t2上添加
max()
。意思是
它只返回我意思是example2,因为max值=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;

请提供样本数据和预期结果。错误似乎很明显。