Query foreign table
# sql
m
Query foreign table
Silly PSQL question: I get
[{ product: "6" }]
using following query:
Copy code
js
       const res = await pool.query(`
            SELECT product
            FROM order_
            WHERE customer = $1
        `, [id]);
How do I get the name of the product instead of the id?
[{ product: "Cloud potatoes" }]
I have a table called 'product' with following columns: id, name and price.
I tried following but get `[]`:
Copy code
js
        const res = await pool.query(`
            SELECT product
            FROM order_
            INNER JOIN product
            ON product.id = order_.id
            WHERE customer = $1
        `, [id]);
Solved it.
Copy code
js
        const res = await pool.query(`
            SELECT name
            FROM product
            INNER JOIN order_
            ON product.id = order_.product
            WHERE customer = $1
            `, [id]);