1

I'm trying to query two relational tables together using Node-PostgreSQL, but getting a syntax error:

    ;(async () => {
        const client = await pool.connect()
        try {
          const res = await client.query('SELECT * FROM "Booking" JOIN "User" ON "User.id"="Booking.renter"')
          console.table(res.rows)
        } finally {
          client.release()
        }
      })().catch(err => console.log(err.stack)) 

The Booking table and the User table is joined by the Booking.renter column and the User.id column, but above code shows:

error: column "User.id" does not exist

Querying a single table works fine:

   const res = await client.query('SELECT * FROM "Booking"')

1 Answer 1

3

You should wrap your table.column individually.

const res = await client.query('SELECT * FROM "Booking" JOIN "User" ON "User"."id"="Booking"."renter"')
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.