Workaround for outer join with an IN operator in Oracle

醉酒当歌 提交于 2019-12-01 06:52:08

First of all, why can't you use proper OUTER JOINs?, you can use them in Oracle without having to do the implicit joins with the (+) syntax. As for your problem, you can use IN:

SELECT p.Name, a.Attribute
FROM People p
LEFT OUTER JOIN Attributes a
ON p.PersonID = a.PersonID AND a.Attribute IN ('Happy','Grouchy')
G. Uest

If you really know the Oracel SQL syntax for a "proper" Oracle database, you could also do this...

SELECT p.Name,
       a.Attribute
  FROM people p,
       (SELECT PersonID,
               Attribute
          FROM attributes
              WHERE Attribute = 'Happy'
              OR Attribute = 'Grouchy') a
  WHERE p.personid = a.personid(+)

The point being that ANSI vs Oracle syntax is a ridiculous comment. Oracle supports both, you whichever is easier/better/manageable for you.

Sorry to answer my own question. To avoid the error ORA-01719, I changed everything to "proper" joins at the advice of @Lamak, and then went with this solution:

SELECT p.Name, a.Attribute
FROM People p
LEFT OUTER JOIN  (SELECT PersonID, Attribute
                  FROM Attributes
                  WHERE Attribute = 'Happy' OR Attribute = 'Grouchy') a
ON (p.PersonID = a.PersonID)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!