Im trying to find a SQL query on the equivalent usage of OUTER APPLY from MSSQL to PostgreSQL but it seems hard to find.
My MSSQL sample query is like this.
hope someone can help me with my problem. thanks in advance.
SELECT table1.col1, table1.col2, Supp.ID, Supp.Supplier
FROM SIS_PRS table1
OUTER APPLY (SELECT TOP 1 ID, SupplierName FROM table2 WHERE table2.ID = table1.SupplierID) AS Supp
It is a lateral join:
However, you can come pretty close in either database with just a correlated subquery:
Also note that in both databases, fetching one row with no
ORDER BY
is suspicious.