I am trying to bring back the maximum valuation number from subval_valuation_cfv for that subcontract and if a valuation doesn't exist for that subcontract, then bring back row but show valuation no as null. I only want to see one row for ever subcontract number even if a valuation doesn’t exist. Here is my query:
SELECT DISTINCT
b.cf$_project AS "Project No",
b.sub_con_no AS "Subcontract Order No",
b.sub_con_name AS "Subcontract Name",
f.valuation_no,
b.supplier_id AS "Supplier ID",
ifsapp.supplier_info_general_api.get_name(b.supplier_id) AS "Supplier Name",
b.cf$_sub_purch_group AS "Cost Code",
b.cf$_sub_purch_group_desc AS "Cost Code Desc",
b.pay_term_id AS "Payment Terms",
b.int_retention AS "Retention %",
f.certificate_no AS "Certificate No",
f.state AS "Certificate Status",
f.cf$_payprocdate AS "Contractual Payment Date",
f.paid_date AS "Date Paid"
FROM
ifsapp.sub_contract_cfv b
LEFT JOIN ifsapp.subval_valuation_cfv f ON b.sub_con_no = f.sub_con_no
WHERE
b.state IN ( 'Active', 'Planned' )
AND upper(b.cf$_project)= 'SO1523'
ORDER BY
"Project No",
"Subcontract Order No"