问题
I'm an Oracle guy trying to convert a query like this to Postgres. Not really understanding all the syntax, etc. Was hoping someone can help?
Oracle Query:
SELECT c.code, c.recommendation, s.suggested, s.sugg_by, a.approved, a.app_by FROM (SELECT code, recommendation FROM recommendations) c, (SELECT code, suggested, sugg_by FROM suggestions) s, (SELECT code, approved, app_by FROM suggestions) a WHERE c.code = s.code(+) AND c.code = a.code(+);
Much appreciated
回答1:
You can try to use OUTER JOIN
SELECT c.code, c.recommendation, s.suggested, s.sugg_by, a.approved, a.app_by
FROM (SELECT code, recommendation FROM recommendations) c
LEFT JOIN (SELECT code, suggested, sugg_by FROM suggestions) s on c.code = s.code
LEFT JOIN (SELECT code, approved, app_by FROM suggestions) a ON c.code = a.code
You seem like didn't need to use subquery, because you didn't do anything in the subquery only select original columns. you can query the table directly.
SELECT
c.code,
c.recommendation,
s.suggested,
s.sugg_by,
a.approved,
a.app_by
FROM recommendations c
LEFT JOIN suggestions s on c.code = s.code
LEFT JOIN suggestions a ON c.code = a.code
来源:https://stackoverflow.com/questions/52372617/oracle-postgres-query