I am trying to make a join on 2 tables. The value I am trying to join is stored in a JSON column on one table and in a TEXT column in the other. Here is my query so far:
SELECT inv.data -> 'total_amount' as iTotalAmount,
inv.data -> 'due_date' as iDueDate,
inv.data -> 'emission_date' as iEmissionDate,
inv.data -> 'customer_name' as iCustomerName,
matc.ch_number as mCompanyHouseNumber,
matc.acc_software_company_name as mAccSoftName
FROM invoices inv, matching_ch_acc_software matc
JOIN mCompanyHouseNumber on iCustomerName
WHERE inv.rating_data IS NOT null
I am however getting the following error:
SQL Error [42P01]: ERROR: relation "mcompanyhousenumber" does not exist Position: 363
I assumed you cant use values defined in the query as part of the JOIN condition? What would be a walk around?
EDIT
updated query:
SELECT inv.data -> 'total_amount' as iTotalAmount,
inv.data -> 'due_date' as iDueDate,
inv.data -> 'emission_date' as iEmissionDate,
inv.data -> 'customer_name' as iCustomerName,
matc.ch_number as mCompanyHouseNumber,
matc.acc_software_company_name as mAccSoftName
FROM invoices inv, matching_ch_acc_software matc
INNER JOIN matching_ch_acc_software
ON (invoices.data -> 'customer_name')::text = matching_ch_acc_software.acc_software_company_name
WHERE inv.rating_data IS NOT null
error:
SQL Error [42P01]: ERROR: invalid reference to FROM-clause entry for table "invoices" Hint: There is an entry for table "inv", but it cannot be referenced from this part of the query. Position: 397
JOIN's are evaluated before implicit, comma separated joins. I.e. theONclause above doesn't know about the invoices table.