0

How can I create the below JOIN in Postgres , This code is from Oracle and it has one join condition which I am not familiar with.

T3.u_ffm_sub_id(+) = T3.u_ffm_id(+)

It is like self join but (+) is on both the sides of condition, So I am confused how to create same in postgres.

Below is the complete code:

SELECT DISTINCT
   CASE
       WHEN MD.u_ffm_id = MD.u_ffm_sub_id THEN MD.patient
       ELSE T3.patient
   END
INTO lRet
FROM UPI.memdate MD,
   UPI.memdate T3
WHERE T3.hmo           = pHmo
AND T3.u_ffm_sub_id(+) = T3.u_ffm_id(+)
AND MD.hmo             = T3.HMO(+)
AND MD.u_ffm_sub_id    = T3.u_ffm_sub_id(+)
AND md.patient         = pPatient;
2
  • 1
    That's Oracle's proprietary (deprecated) way of writing an outer join Commented Dec 2, 2021 at 12:22
  • Check w3schools.com/sql/sql_join.asp Commented Dec 2, 2021 at 12:23

1 Answer 1

2

These are outer joins, and they are easy to translate to standard conforming SQL.

  1. If the (+) is on the right side:

    FROM a, b
    WHERE a.x = b.y(+)
    

    gets translated to

    FROM a LEFT JOIN b
       ON a.x = b.y
    
  2. If the (+) is on the other side, it would be a RIGHT JOIN.

  3. If the (+) is on both sides:

    FROM a, b
    WHERE a.x(+) = b.y(+)
    

    gets translated to

    FROM a FULL JOIN b
       OM a.x = b.y
    
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.