I am working on a Nest.js application using PostgreSQL(postgres.js javascript framework), and I have two tables: addresses
and users
. I am trying to join these tables and filter the results based on an ID. However, I keep encountering the following error:
missing FROM-clause entry for table "a"
Here is the SQL query I am using:
SELECT
a.id,
a.address,
a.landmark,
a.city,
a.state,
a.country,
a.zipcode,
json_build_object(
'id', u.id,
'first_name', u.first_name,
'last_name', u.last_name,
'email', u.email,
'contact_number', u.contact_number,
'image', u.image
) AS user
FROM
addresses a
INNER JOIN
users u
ON
a.user_id = u.id
WHERE
a.id = 102
I have verified that the table names and columns are correct. Despite this, I still encounter the error.
Can anyone help me understand what might be causing this issue and how to resolve it?