How to join sub-queries in PL/SQL?
i need to join subqueries in oracle. This does not work i get a syntax error for the join operation
select s1.key, s1.value, s2.value
from ((select 开发者_如何学JAVAkey, value
from tbl
where id = 1) as s1
join
(select key, value
from tbl
where id = 2) as s2
on s1.contract = s2.contract);
You should select the field you are joining on (contract
) in the inline views:
SELECT s1.key, s1.value, s2.value
FROM (
SELECT contract, key, value
FROM tbl
WHERE id = 1
) as s1
JOIN (
SELECT contract, key, value
FROM tbl
WHERE id = 2
) as s2
ON s1.contract = s2.contract
You had one too many sets of Parenthesis.
SELECT
s1.key,
s1.value,
s2.value
FROM (SELECT
key,
value
FROM tbl
WHERE id = 1) AS s1
JOIN (SELECT
key,
value
FROM tbl
WHERE id = 2) AS s2
ON s1.contract = s2.contract;
Get rid of the outer most parenthesis.
精彩评论