So I have reason
identified as some kind of ID in table1. I need to write query which writes out the belonging meaning of a reason from table 2. I hope my bad english was enough to explain my problem.
table1
id reason
--------------
1 1
2 2
3 1
table2
domain value meaning
------------------------------
table1.reason 1 example1
table1.reason 2 example2
I tried this select but i got error "ORA-01427: single-row subquery returns more than one row" but if I add max()
on t2.meaning
it only returns me meaning example2 because max value = 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;
How can i solve this problem?
The following recommendations will help you in your SQL tuning process.
You'll find 3 sections below:
CREATE INDEX table1_idx_reason ON table1 (reason);
CREATE INDEX table2_idx_domain_value ON table2 (domain,value);
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