i have a T-sql code that i run on SQL server successfully.
SELECT
(SELECT
Address
FROM
customer_address
WHERE
ProspectID = tm.ProspectID
AND TYPE = 'RESIDENCE') AS Residence_Address
FROM
landing.kp_los_trx_master tm
INNER JOIN landing.kp_los_trx_status ts ON
tm.ProspectID = ts.ProspectID
LEFT JOIN landing.kp_los_confins_branch cb ON
tm.BranchID = cb.BranchID
LEFT JOIN landing.kp_los_customer_personal cp ON
tm.ProspectID = cp.ProspectID
LEFT JOIN landing.kp_los_trx_items ti ON
tm.ProspectID = ti.ProspectID
LEFT JOIN landing.kp_los_trx_apk ta ON
tm.ProspectID = ta.ProspectID
LEFT JOIN landing.kp_los_customer_employment cem ON
tm.ProspectID = cem.ProspectID
LEFT JOIN landing.kp_los_customer_emcon ce ON
tm.ProspectID = ce.ProspectID
But, when i want to convert its code to postgresql with the code i created shown below;
SELECT
(SELECT
a.address
FROM
landing.kp_los_customer_address a
inner join landing.kp_los_trx_master b on
a.ProspectID = b.ProspectID
where a."Type" = 'RESIDENCE') AS Residence_Address
FROM
landing.kp_los_trx_master tm
INNER JOIN landing.kp_los_trx_status ts ON
tm.ProspectID = ts.ProspectID
LEFT JOIN landing.kp_los_confins_branch cb ON
tm.BranchID = cb.BranchID
LEFT JOIN landing.kp_los_customer_personal cp ON
tm.ProspectID = cp.ProspectID
LEFT JOIN landing.kp_los_trx_items ti ON
tm.ProspectID = ti.ProspectID
LEFT JOIN landing.kp_los_trx_apk ta ON
tm.ProspectID = ta.ProspectID
LEFT JOIN landing.kp_los_customer_employment cem ON
tm.ProspectID = cem.ProspectID
LEFT JOIN landing.kp_los_customer_emcon ce ON
tm.ProspectID = ce.ProspectID
the result is getting error that:
SQL Error [21000]: ERROR: more than one row returned by a subquery used as an expression
i dont know how to solve of its code, anyone have any idea to help me? thank in advance
LEFT JOINs when the only object you define in theFROM(in the T-SQL) that you use in the query iskp_los_trx_master. In the PostgreSQL you don't reference a single one of the objects in theFROM.