I have this query using outer left self join and it displays what I would expect:
SELECT c.date, u.user_id from order_detail_trans c
LEFT OUTER JOIN order_detail_trans u
ON u.trans_id = c.trans_id
AND u.trans_type = 'UPDATE DETAIL'
I am joining a table to itself because I want one of my columns (user_id) to be populated only for those rows with trans_type of 'UPDATE DETAIL'... but still need to display rows from this table where this is not the trans type. The above query seems to do the trick. I get records with both trans_types, and those with 'UPDATE DETAIL' as trans_type display user_id
I need this to work with the Oracle (+) syntax, here is what I have going off of this source -- https://chartio.com/resources/tutorials/left-and-right-joins-using-the-plus-sign-in-oracle/#performing-outer-joins-using-the-symbol :
SELECT c.date, u.user_id from order_detail_trans c, order_detail_trans u
WHERE u.trans_id(+) = c.trans_id
AND u.trans_type = 'UPDATE DETAIL'
But this doesn't display rows with trans_type of anything other than 'UPDATE DETAIL'
What would be the correct way of re-writing the first query with (+) syntax to render the same results?
Need to include the (+)
Operator on the Condition with the Literal
The older outer join approach requires that you include the (+)
operator for the condition on the literal.
Just put your "retro" mental cap on and return back to the 90's. :)
Here is how it should look with this approach:
SELECT
c
.DATE,
u.user_id
FROM
order_detail_trans c,
order_detail_trans u
WHERE
u.trans_id (+) = c.trans_id
AND u.trans_type (+) = 'UPDATE DETAIL'
Here is an example with the tables, emp
and dept
:
SCOTT@db>SELECT
2 d.deptno,
3 e.job
4 FROM
5 dept d
6 LEFT OUTER JOIN emp e ON d.deptno = e.deptno
7 and e.job = 'CLERK'
8 GROUP BY
9 d.deptno,
10 e.job
11 ORDER BY
12 1,
13 2;
DEPTNO JOB
10 CLERK
20 CLERK
30 CLERK
40
SCOTT@db>SELECT
2 d.deptno,
3 e.job
4 FROM
5 dept d,
6 emp e
7 WHERE
8 d.deptno = e.deptno (+)
9 AND e.job (+) = 'CLERK'
10 GROUP BY
11 d.deptno,
12 e.job;
DEPTNO JOB
20 CLERK
30 CLERK
10 CLERK
40
Believe it or not, I believe most Oracle Applications shops just use this older outer join approach.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.