Skip to content
Advertisement

Invalid reference to FROM-clause entry for table “mc”

I’m trying to get an item “manufacturer” with an array of contacts and each contact contains an array of translations using this query

but I get this error

this is the ER diagram

enter image description here

dummy data example:

I tried to change the structure of the query to solve it but I wasn’t able to fix it.

Since I don’t have much experience with complex SQL queries, I won’t know what is the right way to do this?

Advertisement

Answer

nested queries inside joins can’t access the tables outside, you must use LATERAL joins for it.

as for your dummy data example: to select non-table-like result the JSONB functions as useful

here, the code that selects the structure you need (result is json):

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement