0

I am attempting to effect a join query in node-postgres (pg) with the following function but am getting a syntax error. The problem is the join query, everything else works fine. What is the correct way to format a join query in pg?

exports.bigBook = function(req, res) {
  var bookNumber = req.params.id;
  pool.connect(function(err, client, done) {
   if (err) { return console.error('error fetching client from pool', err);}
   client.query('SELECT * FROM book WHERE id = $1 LEFT JOIN author 
    ON (book.author = author.auth_id)'), [bookNumber], function (err, results) {
    client.release();
    res.send(results.rows);
  };
 })
}

1 Answer 1

1

The LEFT JOIN is part of the FROM clause, so you'll have to move the WHERE clause to the end of the query.

Sign up to request clarification or add additional context in comments.

1 Comment

That did it, I appreciate it.

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.