Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial


Jack Lee
Jack Lee
Full Stack JavaScript Techdegree Student 15,536 Points

How to use Sequalize to query with "JOIN table ON attr=attr"

Here is the table Schema:


  • id: INTEGER,
  • book_id: INTEGER,
  • patron_id: INTEGER,
  • loaned_on: DATE,
  • return_by: DATE,
  • returned_on: DATE

I want to query Loans and its associated tables using sequalize like this:

book.title AS book, 
patron.first_name||' '||patron.last_name AS patron, 
FROM loans 
JOIN books AS book ON loans.book_id=books.id 
JOIN patrons AS patron ON loans.patron_id=patrons.id

More Detailed StackOverflow Question Here

1 Answer

Balazs Peak
Balazs Peak
46,160 Points

You don't need to use the "AS" keyword, and the alias once again, in the "JOIN" section. You've already aliased it before, that is enough. I would bet that this is your problem. Hope this helps. Much love!